To align text to the right margin of a web page using CSS, you can use the text-align
property set to right
. Here is a simple example:
.right-align {
text-align: right;
}
You can apply this CSS class to any HTML element, such as a <div>
, <p>
, or <h1>
, to align the text within that element to the right. Here’s how you might use it in HTML:
<div class="right-align">
This text is aligned to the right margin.
</div>
Alternatively, if you want to set the right alignment for all text within a specific section, you can apply the style directly to that section:
<section style="text-align: right;">
This text will also be aligned to the right.
</section>
Using the text-align: right;
CSS rule is the standard way to achieve right-aligned text.