:right CSS Pseudo Class
Description
The :right pseudo-class in CSS is used to select elements that are aligned or positioned on the right side within their containing block. While it is less commonly used than pseudo-classes like :hover or :first-child, it can be valuable when working with text alignment, directional layouts, or elements that need styling based on their placement relative to the right edge of a container.
This pseudo-class is particularly useful in designs that require different styling for right-aligned elements. For instance, in right-to-left (RTL) language layouts, elements that appear visually on the right side might need unique styles, such as different margin, padding, or text-align adjustments. It allows developers to apply styles conditionally without adding extra classes or relying solely on JavaScript.
Additionally, :right can interact with other pseudo-classes and elements for more advanced styling. For example, it can be combined with :nth-child() to style every right-most element in a sequence or used alongside div containers to visually balance layouts.
Here is a practical example:
<div class="container">
<p class="align-left">Left-aligned text</p>
<p class="align-right">Right-aligned text</p>
</div>
p:right {
text-align: right;
background-color: #f0f0f0;
padding: 10px;
}
In this example, only the paragraph that is positioned on the right side of its container receives the right alignment and background styling. This makes it easier to maintain consistent styling for right-aligned elements across a webpage without adding extra classes manually.
Another practical use is in tables, where you might want numeric values or dates to automatically align to the right:
td:right {
text-align: right;
font-weight: bold;
}
Overall, :right provides a semantic, CSS-native way to target elements based on their visual alignment rather than structural classes, helping maintain cleaner HTML and more responsive designs.
Syntax
:right {
/* ... */
}
Example
Browser Support
The following information will show you the current browser support for the CSS :right pseudo class. Hover over a browser icon to see the version that first introduced support for this CSS psuedo class.
This psuedo class is supported in some modern browsers, but not all.
Desktop
Tablets & Mobile
Last updated by CSSPortal on: 31st December 2025
