You don’t know CSS: Design Tokens Naming Structure (2024)

You don’t know CSS: Design Tokens Naming Structure (1)

Design tokens are a method of abstracting and organizing the design elements of a system into usable and uniform values. By utilizing CSS variables, these tokens promote a more modular and manageable approach to styling for web development.

When building our design system at McAfee, we explored various ways to create sizable collections of tokens, and decided to use ComponentVariantKindModifierPropertyas the most logical structure. This enabled us to have precise control over our components, while also making it simple to find and use them.

Let’s break down each part of this framework:

1. Component: This represents a higher-level UI component, such as a button or any other element in your design system.

2. Variant: Variations of a component might include subtypes or various designs. For example, a button might feature variants like primary, secondary, or tertiary. It’s good practice to not use primary as it is redundant in this formula and adds bloat.

3. Kind: Kinds represent state modifications or contextual variations of a component, such as error, warning, or disabled states.

4. Modifier: Modifiers are additional variations or pseudo-states applied to a component, such as active, pressed, or hovered.

5. Property: This refers to the specific design attribute or property being defined by the design token. Examples include background color, text color, or font size.

Let’s see an example of how this structure might be applied using CSS variables:

:root {
--button-background: #3498db;
--button-color: #ffffff;
--button-error-background: #2ecc71;
--button-error-color: #ffffff;
--button-error-hover-background: #2ecc71;
--button-error-hover-color: #ffffff;
/* secondary */
--button-secondary-background: #2ecc71;
--button-secondary-color: #ffffff;
--button-secondary-error-background: #2ecc71;
--button-secondary-error-color: #ffffff;
--button-secondary-error-hover-background: #2ecc71;
--button-secondary-error-hover-color: #ffffff;
/* … other design tokens */
}

Benefits of Using this Structure:

1. Consistency and Reusability: Design tokens provide a single source of truth for styling, providing a consistent look and feel throughout the application. Reusable tokens make it easy to maintain and update styles.

2. Modularity: The structured approach allows for easy modification of individual components, variants, or states without affecting the entire system.

3. Maintainability: with a clear naming convention and organization, it’s easier to understand, document, and maintain the design system over time.

4. Adaptability: Design tokens make it simpler to adapt the design system to different themes or styles by adjusting the values of the tokens.

Integration with BEM:

BEM and design tokens work together to create an efficient system. BEM’s naming conventions fit perfectly with the components, variants, kind, and modifiers found in design tokens, allowing for the creation of modular and easily maintainable styles.

For example, in the CSS snippet above, BEM classes are used to define different button states and variations, and the corresponding design tokens are applied within these BEM blocks.

/* Example usage with BEM syntax */
.button {
/* default button */
background: var(--button-background);
color: var(--button-color);

&--secondary {
/* button secondary */
background: var(--button-secondary-background);
color: var(--button-secondary-color);
&:hover {
background: var(--button-secondary-hover-background);
color: var(--button-secondary-hover-color);
}
&--error {
/* button secondary error */
background: var(--button-secondary-error-background);
color: var(--button-secondary-error-color);
&:hover {
/* button secondary error hover */
background: var(--button-secondary-error-hover-background);
color: var(--button-secondary-error-hover-color);
}
}
}

&--error {
/* Error state styles */
background: var(--button-error-background);
color: var(--button-error-color);
}

&:active {
/* Active state styles */
background: var(--button-active-background);
color: var(--button-active-color);
}
/* … other styles */
}

We decided that this approach was the best fit for elements with various states, allowing us to accurately manage each one. Even though it involves a lot of coding and repetition at first, the advantages outweigh the other aspects.

Summary

Using design tokens alongside a named convention and BEM syntax helps to organize, remain consistent, and maintain your web project or design system’s look. This is an awesome way of guaranteeing that developers and designers can easily understand the variables in a practical manner without having to spend time searching for them.

You don’t know CSS: Design Tokens Naming Structure (2024)

FAQs

How do you name a design token? ›

Design Token Naming Principles

Make use of context: Include context about the token's usage, such as the component to which it applies or its role in the design system. Keep it brief: Aim for names that are brief and memorable, as well as easy to type and read.

What are CSS design tokens? ›

Design tokens — or tokens, for short — are design decisions, translated into data. They're ultimately a communication tool: a shared language between design and engineering for communicating detailed information about how to build user interfaces.

What are design tokens in Figma? ›

Design tokens are a method for managing design properties and values across a design system. Each token stores a piece of information—such as color, sizing, spacing, font, animations, and so on. To make them easier to refer to, each token also gets a name.

What are token names? ›

Name tokens are the smallest indivisible elements of a name that consist of "white space" or punctuation-delimited strings of characters. Name tokens are usually affixes or stems, though they can sometimes be full name phrases in cases where the smaller grammatical units in a name are written as a single word.

What are the typical design tokens? ›

Types of Design Tokens
  • Color Tokens: Define the color palette used in a design system. ...
  • Typography Tokens: Specify text-related properties. ...
  • Spacing Tokens: Govern the spacing system, including margins, paddings, and gaps. ...
  • Sizing Tokens: Define sizes for components and elements.
Sep 5, 2024

How to use token in CSS? ›

You can access individual tokens using the CSS custom properties mounted to the page, however, it's best to use the token() method. This ensures you have proper prefixes, type checking, and linting so you'll know if a token ever changes, is deleted, or is used incorrectly.

Are design tokens worth it? ›

While it may seem like a lot to maintain, design tokens and the design systems they are part of actually prevent massive amounts of reactive back-work. This proactive approach helps teams avoid the frustration that accompanies developing inconsistent experiences, which can proliferate like a virus across a brand.

How do you manage design tokens? ›

Design token manager: an overview
  1. Centralize your design tokens with the option to import from a number of external sources.
  2. Document your design tokens within your zeroheight styleguides.
  3. Make changes to your design tokens in zeroheight with the ability to create, edit and delete tokens.

How to write a design token? ›

  1. Design tokens point to style values like colors, fonts, and measurements.
  2. Use design tokens instead of hardcoded values.
  3. Each token is named for how or where it's used (for example, md.fab.container.color sets the container color for a FAB)
  4. Even if a token's end value is changed, its name and use remain the same.

What is the difference between design tokens and styles? ›

Styles vs Tokens

Styles and tokens are both ways to store and manage design elements in Figma. However, they have different strengths and weaknesses. Styles are more flexible and can be used to store a wider variety of values. For example, you can use styles to store colors, fonts, spacing, and even animations.

How to organize tokens in Figma? ›

Token tiers and alias tokens: You can create token tiers, allowing you to split your design tokens into different levels of hierarchy. You can also create alias tokens that reference tokens in other tiers, allowing you to keep your tokens organized and consistent.

What is the best practice of naming in Figma? ›

The naming rules include using uppercase for the first letter, separating with a hyphen, using (__) to define variants, and grouping by element with a forward slash. By following these rules, you can create a clean, easy-to-access set of components that can be used within the same file or exported to share with others.

What are the 5 components of design? ›

The elements are your tools or raw materials, much like paints are the basics to a painter. The five elements of interior design include space, line, form, color, and texture. The principles of design relate to how you use these elements and are balance, emphasis, rhythm, proportion and scale, and harmony and unity.

What is the recommended way for naming components? ›

Components. Use descriptive and meaningful names for React components. Use PascalCase (capitalizing the first letter of each word) for component names.

How do you name a crypto token? ›

Choosing the perfect crypto coin name involves understanding your coin's unique value proposition, target audience, and the message you want to convey. The name should be memorable, easy to pronounce, and evoke trust and innovation.

Do tokens have a name? ›

Yes. If an effect creates a token but doesn't specify a name for it, the name of the token is the same as its creature types. So if you get a Goblin Warrior token, for example, that token's name is "Goblin Warrior".

How do I create a unique token? ›

Token Generator options
  1. use a monotonically increasing counter and assign whenever a new request for a unique resource id is made. + simple to use. ...
  2. use hashing function like MD5|SHA1|SHA2 or equivalent to generate a unique hash function. ...
  3. use UUID / GUID. ...
  4. Use PRIMARY key in DB and AUTOINCREMENT in MySQL.
Dec 25, 2022

Top Articles
Which country is the best for forex trading?
Best FCA Regulated Forex Brokers UK: Guide for 2024
Craigslist Pets Longview Tx
Libiyi Sawsharpener
123 Movies Black Adam
Urist Mcenforcer
Usborne Links
Sprague Brook Park Camping Reservations
Nm Remote Access
CSC error CS0006: Metadata file 'SonarAnalyzer.dll' could not be found
New Day Usa Blonde Spokeswoman 2022
Best Cav Commanders Rok
Unit 1 Lesson 5 Practice Problems Answer Key
Gfs Rivergate
Gas Station Drive Thru Car Wash Near Me
Chicken Coop Havelock Nc
2024 U-Haul ® Truck Rental Review
Craigslist In Flagstaff
Uktulut Pier Ritual Site
Honda cb750 cbx z1 Kawasaki kz900 h2 kz 900 Harley Davidson BMW Indian - wanted - by dealer - sale - craigslist
Odfl4Us Driver Login
Glover Park Community Garden
Baldur's Gate 3: Should You Obey Vlaakith?
BJ 이름 찾는다 꼭 도와줘라 | 짤방 | 일베저장소
Cognitive Science Cornell
Dal Tadka Recipe - Punjabi Dhaba Style
Goodwill Of Central Iowa Outlet Des Moines Photos
Cfv Mychart
Wbap Iheart
Frank Vascellaro
Filmy Met
Prévisions météo Paris à 15 jours - 1er site météo pour l'île-de-France
Everything You Need to Know About NLE Choppa
Help with your flower delivery - Don's Florist & Gift Inc.
W B Crumel Funeral Home Obituaries
Gwu Apps
Whitehall Preparatory And Fitness Academy Calendar
Studentvue Columbia Heights
The best Verizon phones for 2024
450 Miles Away From Me
Cox Outage in Bentonville, Arkansas
Pp503063
Qlima© Petroleumofen Elektronischer Laserofen SRE 9046 TC mit 4,7 KW CO2 Wächter • EUR 425,95
Hanco*ck County Ms Busted Newspaper
The Nikki Catsouras death - HERE the incredible photos | Horror Galore
Swsnj Warehousing Inc
Sam's Club Gas Price Sioux City
The Largest Banks - ​​How to Transfer Money With Only Card Number and CVV (2024)
Philasd Zimbra
Affidea ExpressCare - Affidea Ireland
Varsity Competition Results 2022
Latest Posts
Article information

Author: Mrs. Angelic Larkin

Last Updated:

Views: 5822

Rating: 4.7 / 5 (47 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Mrs. Angelic Larkin

Birthday: 1992-06-28

Address: Apt. 413 8275 Mueller Overpass, South Magnolia, IA 99527-6023

Phone: +6824704719725

Job: District Real-Estate Facilitator

Hobby: Letterboxing, Vacation, Poi, Homebrewing, Mountain biking, Slacklining, Cabaret

Introduction: My name is Mrs. Angelic Larkin, I am a cute, charming, funny, determined, inexpensive, joyous, cheerful person who loves writing and wants to share my knowledge and understanding with you.