How to Customize Link and Navigation Styling in Twenty Twenty-One
Content
Many users of the Twenty Twenty-One theme encounter a common issue: unwanted styling on links, particularly a black background that appears when a link is clicked or focused. This behavior is a core part of the theme's accessibility features, designed to provide a clear visual indicator for keyboard navigation. However, it often clashes with custom site designs.
Based on community discussions, this styling is controlled by specific CSS selectors that target the :focus state of links. The good news is that this default behavior can be modified or completely removed using custom CSS.
Common Solutions for Customizing Link Styles
The most effective method for overriding the default link styles is to use the 'Additional CSS' feature in the WordPress Customizer. The following code snippets address the most frequently reported issues.
1. Remove or Change the Click/Focus Background
To completely remove the black background that appears on click (the :active state) and focus, use this CSS:
.site a:focus:not(.wp-block-button__link):not(.wp-block-file__link),
.site a:active:not(.wp-block-button__link):not(.wp-block-file__link) {
background-color: transparent !important;
}
2. Remove the Dotted Outline on Focus
To remove the dotted text decoration that appears on focus, add this rule:
.site a:focus:not(.wp-block-button__link):not(.wp-block-file__link) {
text-decoration: none !important;
}
3. Change the Focus Styling to Custom Colors
If you prefer to keep the accessibility features but change the colors, you can modify the properties. The following example changes the background to blue and the text to red on focus:
.site a:focus:not(.wp-block-button__link):not(.wp-block-file__link) {
background-color: blue !important;
color: red !important;
}
Targeting Specific Areas
You can make your CSS more specific by targeting links in certain parts of your site. For instance, to only remove focus styles from the footer widget area, you would use:
.widget-area a:focus {
background-color: transparent !important;
text-decoration: none !important;
}
Similarly, to target a specific navigation menu item by its ID (which can be found by inspecting the element in your browser), use a selector like this:
#menu-item-34529 a:focus {
/* Your custom styles here */
}
Important Considerations
- Accessibility: Completely removing focus styles can make your site difficult to navigate for users who rely on keyboards. Consider replacing the default styles with a more subtle but still visible alternative, like a border or outline.
- Specificity: The Twenty Twenty-One theme's styles are well-defined. Using
!importantis often necessary to override them, as shown in the examples above. - Testing: Always test changes on different browsers and devices to ensure the desired effect is achieved without breaking other elements.
By using these CSS snippets in the 'Additional CSS' section, you can gain full control over how links appear on your site, ensuring they match your design while maintaining the functionality of the Twenty Twenty-One theme.
Related Support Threads Support
-
How to properly remove the submenu background border?https://wordpress.org/support/topic/how-to-remove-submenu-border/
-
How to prevent images with links from inheriting navigation style?https://wordpress.org/support/topic/how-to-prevent-images-with-links-from-inheriting-navigation-style/
-
Change primary menu and header text colorhttps://wordpress.org/support/topic/change-primary-menu-color-2/
-
Define separate colors for backgrounds and texthttps://wordpress.org/support/topic/define-separate-colors-for-backgrounds-and-text/
-
How to change Options accordion block hoverover colorhttps://wordpress.org/support/topic/how-to-change-options-accordion-block-hoverover-color/
-
Removing link background color on imagehttps://wordpress.org/support/topic/removing-link-background-color-on-image/
-
Remove/re-style caret in dropdown menuhttps://wordpress.org/support/topic/remove-re-style-caret-in-dropdown-menu/
-
Body & Menu Colored Red Outline Around Texthttps://wordpress.org/support/topic/body-menu-colored-red-outline-around-text/
-
Dark mode by default using CSS?https://wordpress.org/support/topic/dark-mode-by-default-using-css/
-
Focus link styles differing local/server for child themehttps://wordpress.org/support/topic/focus-link-styles-differing-local-server-for-child-theme/
-
How to find button classhttps://wordpress.org/support/topic/how-to-find-button-class/
-
Background colour of blockshttps://wordpress.org/support/topic/background-colour-of-blocks/
-
CSS for main navigation changeshttps://wordpress.org/support/topic/css-for-main-navigation-changes/
-
Are global button color variables useless?https://wordpress.org/support/topic/are-global-button-color-variables-useless/
-
How to change the on-click color of links?https://wordpress.org/support/topic/how-to-change-the-on-click-color-of-links/
-
Submenu arrow (toggle) border still blackhttps://wordpress.org/support/topic/submenu-arrow-toggle-border-still-black-2/
-
Block Colorhttps://wordpress.org/support/topic/block-color/
-
Dark mode as default shifthttps://wordpress.org/support/topic/dark-mode-as-default-shift/
-
transparency on textboxhttps://wordpress.org/support/topic/transparency-on-textbox/
-
Sale icon color changehttps://wordpress.org/support/topic/sale-icon-color-change/
-
Change color of Search Bar blockhttps://wordpress.org/support/topic/change-color-of-search-bar-block/
-
Remove black backgroundhttps://wordpress.org/support/topic/remove-black-background/
-
Removing link styles (border/box)https://wordpress.org/support/topic/removing-link-styles-border-box/
-
Menu Bold, Size & Colorhttps://wordpress.org/support/topic/menu-bold-size-color/
-
How to change background color of clicked menu items?https://wordpress.org/support/topic/how-to-change-background-color-of-clicked-menu-items/
-
Footer widget area links stylinghttps://wordpress.org/support/topic/footer-widget-area-links-styling/
-
Changing Blog Background & Text Colourhttps://wordpress.org/support/topic/changing-blog-background-text-colour/
-
Overriding active link styling in header navigationhttps://wordpress.org/support/topic/overriding-active-link-styling-in-header-navigation/
-
change fill color for submenu caret (down arrow)https://wordpress.org/support/topic/change-fill-color-for-submenu-caret-down-arrow/
-
Target Mobile Menu Colorhttps://wordpress.org/support/topic/target-mobile-menu-color/
-
Changing body or header with custom CSS, having trouble getting it to workhttps://wordpress.org/support/topic/changing-body-or-header-with-custom-css-having-trouble-getting-it-to-work/