CSS Accessibility Get Certified
What is CSS Accessibility?
CSS Accessibility means writing styles that make websites usable by as many people as possible, including users with visual, motor, or cognitive impairments. Good accessible CSS focuses on readable text, strong color contrast, visible keyboard focus, generous click targets, and responsive layouts.
Why Accessibility Matters
Accessible design improves usability for everyone and is often a legal requirement. CSS plays a major role by controlling contrast, focus styles, spacing, and responsive behavior. When these details are handled well, more people can use your site successfully.
Key Accessibility Techniques
Step 1: Use Readable Font Sizes
What this code does: Sets a comfortable base font size of 18 px and a line-height of 1.6 so body text is easy to read for most users, including those with mild visual impairments.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
body {
font-family: Arial, sans-serif;
font-size: 18px;
line-height: 1.6;
padding: 24px;
margin: 0;
}
</style>
</head>
<body>
<p>This paragraph is easy to read because it uses a readable font size.</p>
</body>
</html>
Step 2: Use Good Color Contrast
What this code does: Uses a near-black text color (#222) on a pure white background. This high-contrast combination meets WCAG contrast guidelines and remains readable for most users, including those with low vision.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
body {
background: white;
color: #222;
font-size: 18px;
font-family: Arial, sans-serif;
padding: 24px;
margin: 0;
}
</style>
</head>
<body>
<h2>Accessible Colors</h2>
<p>Dark text on a light background improves readability.</p>
</body>
</html>
Step 3: Keep Keyboard Focus Visible
What this code does: Adds a clear 3 px blue outline when a button receives keyboard focus. This lets keyboard users (and screen-reader users) always see which interactive element is currently active.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
body {
font-family: Arial, sans-serif;
padding: 24px;
margin: 0;
}
.demo-btn {
padding: 12px 20px;
font-size: 16px;
cursor: pointer;
}
.demo-btn:focus {
outline: 3px solid blue;
outline-offset: 2px;
}
</style>
</head>
<body>
<button class="demo-btn">Press Tab to Focus</button>
</body>
</html>
Step 4: Increase Clickable Area
What this code does: Gives the button generous padding (15 px vertical, 30 px horizontal) so the clickable area is large enough for easy mouse clicks and touch taps, which is especially helpful for users with motor difficulties.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
body {
font-family: Arial, sans-serif;
padding: 24px;
margin: 0;
}
.demo-btn {
padding: 15px 30px;
font-size: 18px;
background: #007BFF;
color: white;
border: none;
border-radius: 6px;
cursor: pointer;
}
</style>
</head>
<body>
<button class="demo-btn">Accessible Button</button>
</body>
</html>
Step 5: Create a Responsive Layout
What this code does: Constrains the content width with max-width and makes images fluid with max-width: 100%. The layout stays readable on phones, tablets, and desktops without horizontal scrolling.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
.demo-container {
max-width: 700px;
margin: auto;
padding: 20px;
}
.demo-container img {
max-width: 100%;
height: auto;
display: block;
border-radius: 8px;
}
</style>
</head>
<body>
<div class="demo-container">
<h2>Responsive Content</h2>
<p>This layout adjusts automatically to different screen sizes.</p>
<img src="https://picsum.photos/600/250" alt="Responsive Image">
</div>
</body>
</html>
Complete CSS Accessibility Example
What this code does: Combines readable typography, high color contrast, a large clickable button, and a highly visible keyboard focus style into one accessible page that demonstrates the main techniques covered in this lesson.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
body {
font-family: Arial, sans-serif;
font-size: 18px;
line-height: 1.6;
background: #ffffff;
color: #222;
margin: 0;
padding: 30px;
}
.demo-btn {
background: #007BFF;
color: white;
padding: 12px 24px;
border: none;
border-radius: 6px;
cursor: pointer;
font-size: 16px;
}
.demo-btn:focus {
outline: 3px solid orange;
outline-offset: 2px;
}
.demo-btn:hover {
background: #0056b3;
}
</style>
</head>
<body>
<h1>Accessible Webpage</h1>
<p>This page uses readable fonts, high color contrast, and a visible keyboard focus.</p>
<button class="demo-btn">Learn CSS</button>
</body>
</html>
Advantages of CSS Accessibility
Best Practices
- Use readable font sizes (at least 16 px for body text) and sufficient line spacing.
- Choose text and background colors with good contrast (aim for WCAG AA or higher).
- Always keep keyboard focus indicators visible — never remove the outline without a clear replacement.
- Provide large clickable areas for buttons and links (at least 44 × 44 px is a common target).
- Build responsive layouts so content remains usable on every screen size.
- Do not rely only on color to communicate information (use text or icons as well).
- Use semantic HTML elements together with accessible CSS.
- Test your website using only the keyboard and on different devices and screen sizes.
Web Resources on CSS Accessibility
1. MDN Web Docs : CSS and JavaScript accessibility best practices
2. MDN Web Docs : Accessibility
3. Stanford University IT : The Impacts of CSS on Accessibility
4. CSS Tricks.com : Improving the Accessibility of 24 ways
Click “Run Code” to see the result here.
CSS Syntax Example
The CSS syntax consists of a selector and a declaration block.
h1 { color: blue; font-size: 36px;}Selector: h1 – targets all <h1> elements
Property: color and font-size
Value: blue and 36px
Your CSS Applied Below:
This is an H1 heading with your CSS
This is an H2 heading (not affected)
This paragraph is not affected by the h1 selector.
Welcome to CSS
This page is styled using CSS.
The heading and paragraph use your CSS rules.
- List item with your styles
- Another list item
🧪 Test Your CSS Code
Edit the CSS code on the left and click “Run Code” to see the result on the right.
Click “Run Code” to see the result here.