Skip to main content

The <style> Element

As defined in the HTML Living Standard, the <style> element contains CSS styling information for the document. It is typically placed within the <head>.

Example:
<style>
  body {
    font-family: sans-serif;
    color: #333;
  }
</style>

While external stylesheets are preferred for maintainability, internal styles are useful for critical CSS that must load immediately to prevent layout shift.

View HTML Living Standard: The style element

Accessibility Impact: Visual Presentation

The CSS within a <style> block directly controls the accessibility of the user interface.

WCAG Requirement: Use of Color

Success Criterion 1.4.1 (Level A): Use of Color.

Color should not be used as the only visual means of conveying information, indicating an action, prompting a response, or distinguishing a visual element. When writing CSS in a <style> block, ensure that errors or important states are indicated by more than just a color change (e.g., add an icon or a border).

Understand SC 1.4.1: Use of Color

Best Practices for Accessible Styling

A11y Tip: High Contrast Mode

When using internal styles, be mindful of users in "High Contrast Mode" (Windows). Use the system-colors or avoid hard-coding colors for elements that should adapt to the user's OS theme.