Skip to content Accessibility

An Accessible Current Page Navigation State

Design and technical considerations behind the icon that indicates what page you're currently on.

Published

Categories

Introduction #

Colour is an effective way to convey meaning on the web. For example, the current page "Blog" on this sites header is highlighted in orange.

The orange colour is accompanied by an icon the double chevron – which is not just a cosmetic detail – but serves a functional purpose to those with low or colour vision deficiencies.

Screenshot comparing this websites navigation in colour and black and white.
Emulating vision deficiencies using Chrome DevTools provides insights into how people with vision deficiencies view your site. In this example the icon provides a visual indicator (alongside colour) to reflect the current page.

CSS background image #

Originally the double chevron was applied using CSS background image due to the simplicity of positioning it with background-position:

Programming language (abbreviated): css

.site-header a[aria-current='page'] {
background-image: url('/img/icons/chevron-double-up.svg');
background-repeat: no-repeat;
background-position: center bottom;
}

Whilst fulfilling the need to supplement colour with a second visual indicator, using CSS had its disadvantages.

Firstly the icon colour had to be hard coded in the SVG:

Programming language (abbreviated): svg

<svg fill="rgba(206, 128, 5, 1)" ...></svg>

This incurred a maintenance cost should the accent colour (currently orange) change in future. It is also less flexible should the icon be consumed in other contexts (that use other colours).

Secondly the background image (being an external resource reliant on a network request) had the risk of the SVG file failing to load.

And thirdly slow networks suffered a noticeable lag between displaying the text "Blog" and its accompanying icon:

Screenshot of navigation before and after icon is loaded.
Throttling the network in Chrome DevTools to simulate a slow 3G connection enables the performance tab to capture the lag between rendering the HTML and displaying the CSS background image.

Inlining the SVG #

Inlining the SVG in the HTML was a better approach that nullified these drawbacks of CSS background image.

Programming language (abbreviated): html

<a href="/blog/" aria-current="page">
Blog

<svg
xmlns="http://www.w3.org/2000/svg"
fill="currentColor"
width="1em"
height="1em"
viewbox="0 0 24 24"
aria-hidden="true"
focusable="false"
>

<path
fill-rule="evenodd"
d="M4.293 15.707a1 1 0 010-1.414l5-5a1 1 0 011.414 0l5 5a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414 0zm0-6a1 1 0 010-1.414l5-5a1 1 0 011.414 0l5 5a1 1 0 01-1.414 1.414L10 5.414 5.707 9.707a1 1 0 01-1.414 0z"
clip-rule="evenodd"
/>

</svg>
</a>

The hard coded colour could be replaced with fill="currentColor" giving CSS full control of the SVG colour in this and other contexts.

Two double chevron icons. One orange and the other pink.
Using fill="currentColor" allows an SVG to inherit its colour from the surrounding context.

Eliminating the network request (by inlining the SVG) guaranteed the icon is always visible (assuming the HTML is). And ensured the text "Blog" and icon are always shown together in a synchronized fashion (regardless of internet speeds).

One of the temptations of using CSS was easily positioning the icon with background position. However using a combination of left and transform offered the same result and flexibility:

Programming language (abbreviated): css

.site-header a[aria-current='page'] svg {
position: absolute;
bottom: 0;
left: 50%;
transform: translateX(-50%);
}

Using left: 50% with transform: translateX(-50%) decouples the position of the SVG from its width and height. In other words the icon is always centered regardless of its dimensions.

Three centered double chevron icons of different sizes.
left: 50% moves the left side of the SVG to the center of its parent (the anchor). And translateX(-50%) shifts the SVG leftwards by half of its width (SVG width / 2).

Accessibility #

To be accessible the inline SVG needed a couple of things.

Firstly the icon is hidden from assistive technologies such as screen readers using the aria-hidden attribute. Otherwise some screen readers announce "group" upon discovering it.

Programming language (abbreviated): html

<svg
xmlns="http://www.w3.org/2000/svg"
fill="currentColor"
width="1em"
height="1em"
viewBox="0 0 24 24"
aria-hidden="true"
focusable="false"
>

<!-- ... -->
</svg>

Secondly the SVG should not allow focus. Using focusable="false" prevents a second tab stop in Internet Explorer, which if permitted would be both unintuitive and undesirable.

Thirdly the SVG width and height use ems instead of pixels. Ems are relative units which allow the icon size to scale proportionality to the current/parent element, or user-defined font-size (whereas pixels don't).

Three icons at different sizes based on Google Chromes font size settings.
Relative units allow SVGs to adapt to the users preferred font size. By default the computed SVG size is 20 by 20 pixels. However changing the font size to "Large" updates the icon size to 25 pixels.

It is important for inline SVGs to have a width and height defined in the HTML. Not doing so (and making CSS responsible for the width/height) is risky since the CSS file could fail to load, resulting in supersized icons.

Two SVGs side by side. The left one without a defined width or height. The right one with a defined width and height.
An SVG without a defined width or height will expand to fill all available space. Seeing SVGs consume the full width of a browser (when CSS fails to load) is not an uncommon sight.

Fourthly the colour of the icon needs sufficient contrast with the background colour. Tools such as Firefoxes accessibility inspector and WebAims contrast checker can verify the ratio between foreground and background colours.

Lastly you may have noticed the anchor containing the icon has the attribute aria-current="page".

Programming language (abbreviated): html

<a href="/blog/" aria-current="page">
Blog

<!-- svg -->
</a>

This allows some screen readers to convey additional context by announcing "Blog, current page link" to indicate (unsurprisingly) what the current page is. Léonie Watson explains using the aria-current attribute in great detail.

And that is a wrap!

To recap #

  • Colour alone cannot be used to convey meaning. It should be supplemented with a second visual indicator (such as an icon).
  • Before using CSS background images consider any limitations or drawbacks an additional network request incur.
  • Using left: 50% with transform: translateX(-50%) horizontally centers an element regardless of its size.
  • Hide presentational SVGs from screen readers using aria-hidden="true".
  • Prevent SVG focus in Internet Explorer with focusable="false".
  • Relative units (ems) enable SVGs to scale proportionality, unlike pixels.
  • Inline SVGs should define their width and height in case CSS fails to load.
  • Icons should have sufficient colour contrast against their background colour.
  • The aria-current attribute provides more context to assistive technologies.

Filed under

  • Accessibility

4617作文网给新农村村庄起名周易风水转运xzt一周易文化测算周易起名男宝宝起名解 梦梦见房子塌了周公解梦白先勇解读红楼梦党姓起名字大全起名讲究学问用熙起名字男宝宝火锅鸡起名大全两个字周期刚完容易怀孕吗食品公司起什么名男孩起名杨文开头从小一起长大微信群名周易生辰八字算命准吗周易六十四卦卦象全解童姓女宝宝起名生肖生辰八字算命老版周公解梦原版实用免费瓷都取名起名大全网中医周易工商企业起名算命运婚姻周公解梦大全查询老公出轨牛杂起名大全单的起名复合材料起名房地产起名字大全免费姓名打分起网淀粉肠小王子日销售额涨超10倍罗斯否认插足凯特王妃婚姻让美丽中国“从细节出发”清明节放假3天调休1天男子给前妻转账 现任妻子起诉要回网友建议重庆地铁不准乘客携带菜筐月嫂回应掌掴婴儿是在赶虫子重庆警方辟谣“男子杀人焚尸”国产伟哥去年销售近13亿新的一天从800个哈欠开始男孩疑遭霸凌 家长讨说法被踢出群高中生被打伤下体休学 邯郸通报男子持台球杆殴打2名女店员被抓19岁小伙救下5人后溺亡 多方发声单亲妈妈陷入热恋 14岁儿子报警两大学生合买彩票中奖一人不认账德国打算提及普京时仅用姓名山西省委原副书记商黎光被逮捕武汉大学樱花即将进入盛花期今日春分张家界的山上“长”满了韩国人?特朗普谈“凯特王妃P图照”王树国3次鞠躬告别西交大师生白宫:哈马斯三号人物被杀代拍被何赛飞拿着魔杖追着打315晚会后胖东来又人满为患了房客欠租失踪 房东直发愁倪萍分享减重40斤方法“重生之我在北大当嫡校长”槽头肉企业被曝光前生意红火手机成瘾是影响睡眠质量重要因素考生莫言也上北大硕士复试名单了妈妈回应孩子在校撞护栏坠楼网友洛杉矶偶遇贾玲呼北高速交通事故已致14人死亡西双版纳热带植物园回应蜉蝣大爆发男孩8年未见母亲被告知被遗忘张立群任西安交通大学校长恒大被罚41.75亿到底怎么缴沈阳一轿车冲入人行道致3死2伤奥运男篮美国塞尔维亚同组周杰伦一审败诉网易国标起草人:淀粉肠是低配版火腿肠外国人感慨凌晨的中国很安全男子被流浪猫绊倒 投喂者赔24万杨倩无缘巴黎奥运男子被猫抓伤后确诊“猫抓病”春分“立蛋”成功率更高?记者:伊万改变了国足氛围奥巴马现身唐宁街 黑色着装引猜测

4617作文网 XML地图 TXT地图 虚拟主机 SEO 网站制作 网站优化