Why Semantic HTML?
Semantic HTML provides meaning to your markup, making it more accessible to assistive technologies and search engines. Oat UI extends this principle by styling semantic elements directly, eliminating the need for CSS class proliferation. Traditional approach with classes:Data Attributes for Variants
Oat UI usesdata-* attributes to indicate semantic variants, keeping your HTML clean and meaningful. This approach separates content from presentation while maintaining clarity.
Button Variants
Buttons usedata-variant to indicate their semantic purpose:
Data attributes like
data-variant="danger" convey semantic meaning (this action is destructive), while classes like .outline or .ghost indicate visual style only.Form Fields
Form elements usedata-field to create properly spaced and associated fields:
data-field="error":
Automatic Styling of Native Elements
Oat UI styles native HTML elements automatically without requiring any classes. This encourages the use of proper semantic markup.Typography
Headings, paragraphs, links, and text formatting elements are styled contextually:Lists
Ordered and unordered lists are styled automatically:Form Elements
All form elements receive consistent styling without classes:Minimal Use of Classes
While Oat UI prioritizes semantic HTML, classes are used sparingly for visual variations that don’t carry semantic meaning:Visual Style Classes
Component Classes
Some components require a class for identification since they don’t have semantic HTML equivalents:Accessibility Benefits
The semantic-first approach provides significant accessibility advantages:- Screen readers can better understand and navigate your content
- Keyboard navigation works automatically with native elements
- ARIA attributes are more effective when paired with semantic HTML
- Focus states are handled consistently (see 00-base.css:177-180)
Best Practices
Use the right element for the job
Use the right element for the job
Always use semantic HTML elements (
<button>, <nav>, <article>, etc.) instead of generic <div> or <span> elements with classes.Let data attributes convey meaning
Let data attributes convey meaning
Use
data-* attributes for semantic variants that change the purpose or context of an element.Use classes only for visual styling
Use classes only for visual styling
Reserve classes for purely visual variations that don’t affect the semantic meaning.
Combine semantic HTML with ARIA
Combine semantic HTML with ARIA
Enhance accessibility by pairing semantic elements with appropriate ARIA attributes.
Examples from Components
Button Groups
Semantic<menu> element with list items:
Input Groups
Semantic<fieldset> with the .group class:
Form Layout
Semantic<label> elements wrapping inputs:
By following Oat UI’s semantic-first approach, you’ll write cleaner HTML, create more accessible interfaces, and reduce the cognitive overhead of managing countless utility classes.