{"id":1120,"date":"2024-03-13T15:36:37","date_gmt":"2024-03-13T21:36:37","guid":{"rendered":"https:\/\/frontendmasters.com\/blog\/?p=1120"},"modified":"2024-03-13T15:36:37","modified_gmt":"2024-03-13T21:36:37","slug":"you-want-border-color-transparent-not-border-none","status":"publish","type":"post","link":"https:\/\/frontendmasters.com\/blog\/you-want-border-color-transparent-not-border-none\/","title":{"rendered":"You Want border-color: transparent, Not border: none"},"content":{"rendered":"\n<p>If you find yourself removing a border from an element that has a border and are tempted to use <code>border: 0<\/code> , <code>border: none<\/code>, or <code>outline: none<\/code>, I\u2019d urge you to stop for a moment and reconsider. It\u2019s like <a href=\"https:\/\/fs.blog\/chestertons-fence\/\">the old G.K. Chesterton saying about fences<\/a>:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>Do not remove a fence until you know why it was put up in the first place.<\/p>\n<\/blockquote>\n\n\n\n<p>In the case of interactive form controls (inputs, textareas, buttons, etc.), those pesky borders were put there because they have an accessibility benefit when using High Contrast Mode, a feature <a href=\"https:\/\/webaim.org\/projects\/lowvisionsurvey2\/#at\">used by 30.6% of low-vision users<\/a>. Usually when we\u2019re talking about High Contrast Mode in web development we\u2019re specifically referencing Windows High Contrast Mode, but nearly every desktop and mobile operating system has contrast settings, each behaving a little differently. <a href=\"https:\/\/blogs.windows.com\/msedgedev\/2020\/09\/17\/styling-for-windows-high-contrast-with-new-standards-for-forced-colors\/\">Windows High Contrast flattens all colors<\/a> to black on white with blue accents (or white on black with yellow accents) and remove all background images from the document.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"556\" src=\"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/03\/Untitled-4.png?resize=1024%2C556&#038;ssl=1\" alt=\"\" class=\"wp-image-1223\" srcset=\"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/03\/Untitled-4.png?resize=1024%2C556&amp;ssl=1 1024w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/03\/Untitled-4.png?resize=300%2C163&amp;ssl=1 300w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/03\/Untitled-4.png?resize=768%2C417&amp;ssl=1 768w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/03\/Untitled-4.png?resize=1536%2C835&amp;ssl=1 1536w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/03\/Untitled-4.png?w=1971&amp;ssl=1 1971w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><\/figure>\n\n\n\n<p>If we look at some thing more interactive like the comment form on the Boost blog, we can see how the \u201cPost Comment\u201d button loses a bit of punch in High Contrast Mode and might be mistaken as text floating on the page.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"613\" src=\"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/03\/Untitled-1-2.png?resize=1024%2C613&#038;ssl=1\" alt=\"\" class=\"wp-image-1224\" srcset=\"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/03\/Untitled-1-2.png?resize=1024%2C613&amp;ssl=1 1024w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/03\/Untitled-1-2.png?resize=300%2C180&amp;ssl=1 300w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/03\/Untitled-1-2.png?resize=768%2C460&amp;ssl=1 768w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/03\/Untitled-1-2.png?resize=1536%2C920&amp;ssl=1 1536w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/03\/Untitled-1-2.png?resize=2048%2C1226&amp;ssl=1 2048w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/03\/Untitled-1-2.png?w=3000&amp;ssl=1 3000w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><\/figure>\n\n\n\n<p>To make that button look more like a button in high-contrast mode, we remove the <code>border: 0<\/code> and instead use <code>border-color: transparent<\/code> we get a control that looks like a button for low-vision users as well.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"613\" src=\"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/03\/Untitled-2-2.png?resize=1024%2C613&#038;ssl=1\" alt=\"\" class=\"wp-image-1226\" srcset=\"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/03\/Untitled-2-2.png?resize=1024%2C613&amp;ssl=1 1024w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/03\/Untitled-2-2.png?resize=300%2C180&amp;ssl=1 300w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/03\/Untitled-2-2.png?resize=768%2C460&amp;ssl=1 768w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/03\/Untitled-2-2.png?resize=1536%2C920&amp;ssl=1 1536w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/03\/Untitled-2-2.png?resize=2048%2C1226&amp;ssl=1 2048w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/03\/Untitled-2-2.png?w=3000&amp;ssl=1 3000w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><\/figure>\n\n\n\n<p>Sighted users will never know the difference! So instead of removing the border, try setting <code>border-color<\/code> to <code>transparent<\/code> instead:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">border-color<\/span>: <span class=\"hljs-selector-tag\">transparent<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The same trick works for overriding <code>outline<\/code> , set <code>outline-color<\/code> to <code>transparent<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">outline-color<\/span>: <span class=\"hljs-selector-tag\">transparent<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Oops! I\u2019ve already nuked my borders<\/h2>\n\n\n\n<p>If you\u2019ve already removed borders everywhere and want to support High Contrast Mode (you do) but don\u2019t want to re-architect your entire CSS, you can use the <code>forced-colors<\/code> media query to detect High Contrast Mode and layer in styling as necessary:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-comment\">\/* Example code, do not use *\/<\/span>\n<span class=\"hljs-keyword\">@media<\/span> (<span class=\"hljs-attribute\">forced-colors:<\/span> active) {\n  <span class=\"hljs-selector-tag\">input<\/span>, <span class=\"hljs-selector-tag\">textarea<\/span>, <span class=\"hljs-selector-tag\">button<\/span> {\n    <span class=\"hljs-attribute\">border<\/span>: <span class=\"hljs-number\">1px<\/span> solid transparent<span class=\"hljs-meta\">!important<\/span>;\n  }\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>There are other places (e.g. text on images) where the <code>forced-colors<\/code> media query can get you out of a jam.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Testing forced-colors<\/h2>\n\n\n\n<p>To test <code>forced-colors<\/code> the easiest way is to emulate <code>forced-colors<\/code> inside Chrome DevTools. There are two easy ways in any version of Chromium browser and an even easier way in Microsoft Edge.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Chrome DevTools &gt; Three Dots Menu &gt; More Tools &gt; Rendering &gt; Emulate CSS media feature forced-colors<\/li>\n\n\n\n<li>Chrome DevTools &gt; Open Command Palette (CMD + Shift + P) &gt; Search for \u201cEmulate CSS forced-colors: active\u201d<\/li>\n<\/ol>\n\n\n\n<p>Edge DevTools has an easy way to access color emulation from the Device Emulation Screen as well.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Edge DevTools &gt; Device Emulation &gt; Open Eye Droppers dropdown in top toolbar &gt; forced-colors: active<\/li>\n<\/ul>\n\n\n\n<p>One other aspect to consider is that folks using high-contrast mode are often using it with a screen magnifier or 200%~400% browser zoom as well. So be sure to test those situations as well.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">High-Contrast Mode keeps you honest about color usage<\/h2>\n\n\n\n<p>Testing in High-Contrast Mode is probably something you\u2019re not doing, but that\u2019s okay because you can start today. While it\u2019s worthwhile to test High-Contrast Mode just to support low-vision users, because it aggressively flattens and removes colors it has a knock-on effect of showing places where you\u2019ve over-relied on color to make elements or states distinct, which is another accessibility error in itself (<a href=\"https:\/\/www.w3.org\/WAI\/WCAG21\/Understanding\/use-of-color.html\">\u00a71.4.1<\/a>).<\/p>\n\n\n\n<p>High-Contrast Mode may seem like a far out edge case, but it\u2019s not. Lots of folks depend on it. Understanding High-Contrast Mode and its limitations are a step on the pathway to becoming a better front-end developer.<\/p>\n\n\n\n<p>Thanks <a href=\"https:\/\/melanie.codes\/\">Melanie Sumner<\/a> for the inspiration for this post and check out her work on <a href=\"https:\/\/continuousaccessibility.com\/\">Continuous Accessibility<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you find yourself removing a border from an element that has a border and are tempted to use border: 0 , border: none, or outline: none, I\u2019d urge you to stop for a moment and reconsider. It\u2019s like the old G.K. Chesterton saying about fences: Do not remove a fence until you know why [&hellip;]<\/p>\n","protected":false},"author":13,"featured_media":1228,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"sig_custom_text":"","sig_image_type":"featured-image","sig_custom_image":0,"sig_is_disabled":false,"inline_featured_image":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[49,7,130],"class_list":["post-1120","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog-post","tag-accessibility","tag-css","tag-high-contrast-mode"],"acf":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/03\/high-contrast-thumb.jpg?fit=1000%2C500&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/1120","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/comments?post=1120"}],"version-history":[{"count":6,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/1120\/revisions"}],"predecessor-version":[{"id":1231,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/1120\/revisions\/1231"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/media\/1228"}],"wp:attachment":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/media?parent=1120"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/categories?post=1120"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/tags?post=1120"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}