Card: Text Alignment

Text Alignment

The Chessmaster of Words

Text alignment, hyphenation, and dividing lines are like the moves in a grandmaster’s chess game, where every word is strategically placed. Aligned to the left, like the reliable pawn, it holds its ground as the default position. Centered, like the king commanding the board, it draws all attention to itself. Aligned to the right, like the graceful queen, it adds finesse and elegance to the edges of your text.

Hyphenation plays the role of the knight, leaping deftly over gaps and ensuring a smooth reading experience. And then there’s the dividing line, the rook, firmly marking sections and enforcing clear boundaries. With these moves in your arsenal, your text will not only be harmonious but a tactical masterpiece worthy of applause.

Perfect Text Arrangement

Align, Divide, Balance — So Your Text Always Looks Good.

Token: text-align center

Alignment

The Arrangement of Words

Text alignment acts as the conductor of your words. Left-aligned provides a steady foundation, right-aligned whispers a touch of creativity, and centered bestows your lines with an air of authority and significance.

h1 {
    text-align: center;
}

This property assigns positions to text. The value left (default) for left alignment, center for centering, and right for right alignment.

Token: text-align justify

Justification

Words in Perfect Formation

In justified text, words march in perfect alignment, both left and right. This strict, orderly arrangement creates a formal, respectful impression where no word dares step out of line.

p {
   text-align: justify;
}

Your text will now be displayed in justified alignment.

Token: hyphens

Hyphenation

The Breathing Spaces of Words

Hyphenation ensures that long words are neatly broken into manageable chunks. Like catching your breath mid-run, it helps maintain the flow of reading while avoiding unsightly gaps in the text.

p {
    hyphens: auto;
}

The hyphens property enables hyphenation and requires the language to be specified in the HTML tag e.g., <html lang=”en”> .

Token: hr in CSS

Divider Line – Horizontal Rule

The Stylish Boundary

With CSS, the humble <hr> element transforms into an elegant line, acting as an invisible barrier to separate your sections. You can customize its color, thickness, and style to add a touch of depth and structure to your page.

hr {
    border: none;
    height: 20px;
    background-color: red;
}

border: none; removes the default border. height: 2px; sets the line’s height. background-color: red; changes the line’s color.

Token: text-wrap

Text Wrapping and Balance

Harmonious Text Styling

With text-wrap: balance;, your text gracefully spreads across multiple lines, creating a visually balanced appearance. But if you prefer something flowing and smooth, opt for text-wrap: pretty;. It prevents orphaned words from lingering alone at the end of a line, ensuring an elegant and continuous text flow.

.balance {
    text-wrap: balance;
}

.pretty {
    text-wrap: pretty;
}

While balance evenly distributes text across lines, pretty keeps the text fluid, avoiding single words at the line’s end. However, be aware that pretty still has limited browser support.

CSS
.container {
    max-width: 400px;
    margin: 0 auto;
}

/* Left-align is default */

.center-align {
    text-align: center;
}

.right-align {
    text-align: right;
}

.balance {
    text-wrap: balance;
}

.justify-text {
    text-align: justify;
}

.hyphenated {
    hyphens: auto;
}

hr {
    border: none;
    height: 20px;
    background-color: darkgreen;
}
Scroll to Top