Allow end-user styling overrides
Tags: a11y, css
Published: 2020-06-12 21:51:46

---
title: Allow end-user styling overrides
published: true
description: While there are different ways of adding CSS into your documents, some types should be avoided to allow for some end-user customization.
tags: a11y,css
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/ma0cu0f7bkg4ylit6a34.png
series: Web Accessibility with CSS
---

When starting with CSS, you learn that there are [three ways in which styles can be added into an HTML page](https://developer.mozilla.org/en-US/docs/Learn/CSS/First_steps/How_CSS_is_structured#Applying_CSS_to_HTML):

- **External styles**: in a separate file added using `<link>`.
- **Internal styles**: inside a `<style>` tag in the HTML document itself.
- **Inline styles**: applied directly to a tag using the `style` attribute.

The styles then _cascade_ down, being applied from the outside to the inside. So inline styles will take priority over internal styles, that will have more priority than external styles.

With that in mind, it looks like the developer is in complete control of the document styling, but there are a couple of cases that fall "outside" of that:

- **Internal browser styles**: these are the default styles that the browser applies to the HTML elements. They have the lowest priority, but not all of them can be overridden (e.g. the widgets for different inputs).
- **End-user styles**: these are styles that are applied by the user (normally using one of the 3 methods described above via a plugin/extension).

Now you will say: "_Wait a second! If end-user styles are applied using one of the three methods, then it can be overridden by the developer styles!_"... and you will be 100% correct.

And that is the point of this article: **developers should write CSS in a way that can be overridden by the user**.

<figure>
![Order of the cascaded styles: browser, external, internal, inline, and user-generated styles](https://dev-to-uploads.s3.amazonaws.com/i/dor8jup7wkkc63tz7v55.png)
<figcaption>Figure: How styles "cascade" and should be applied into the document</figcaption>
</figure>

There are many [reasons why an end-user may want to provide their own set of styles](https://webaim.org/techniques/css/#intro): people suffering from colorblindness could want to override some of the color values to make the site easier to navigate, people with visual difficulties may opt for larger font sizes or zooming on some elements to be able to read better, or people with cognitive or learning disabilities may opt for applying a completely font family altogether.

It is our website and our code, but it is the user's browser and experience. While we, as developers, can set up the general experience, we should allow space for some customization from the user side.

So, how can developers write CSS that can be easily overridden? Mainly following these three steps:

1. Stop using inline styles.
2. Do not use `!important`.
3. Use relative units.

The inline styles are a bad idea in general: they tend to require more coding, they are not as flexible... and they take priority over the user-defined styles. Avoid them whenever it is possible.

The [`!important` keyword](https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity#The_!important_exception) will override any other CSS declaration (including the user defined styles). Plus it is considered bad practice in general, so avoid it.

Using relative units allow for some additional flexibility. Users could define the root size at the browser level and that way all the content would automatically adapt to the new sizing.

The last two points can be extended further and will be revisited in upcoming posts.

----

**Do not force CSS styles onto the user. Write CSS in a way in which users could override it easily if needed**.