⇧
vadnica-logo
Editor My Blog Password Manager Finance My Services About the Project Telegram O meni O meni

CSS Text

In an HTML document, we can style text using various CSS properties. We will learn about text alignment, style changes, transformation, spacing, and shadowing. Every block-level HTML element by default takes up the entire available width (extends left and right); however, if we set width and height, we prevent the element from stretching to the edges.

EXAMPLE
RESULT
Property Example Description
Color and Fonts
colorcolor: #333; Sets the text color
font-familyfont-family: Arial, sans-serif; Specifies the font of the text
font-sizefont-size: 16px; Specifies the font size
font-stylefont-style: italic; Specifies the font style (normal, italic, oblique)
font-weightfont-weight: bold; Specifies the font weight (normal, bold, 100-900)
fontfont: 16px Arial; Shorthand syntax for all font properties
Alignment
text-aligntext-align: center; Specifies text alignment (left, right, center, justify)
text-align-lasttext-align-last: right; Specifies alignment of the last line of a paragraph
vertical-alignvertical-align: middle; Specifies vertical alignment of inline elements
text-indenttext-indent: 20px; Specifies the indentation of the first line of text
Spacing
line-heightline-height: 1.6; Specifies vertical spacing between lines
letter-spacingletter-spacing: 2px; Specifies spacing between characters
word-spacingword-spacing: 5px; Specifies spacing between words
Decoration and Transformation
text-decorationtext-decoration: underline; Specifies text decoration (underline, overline, line-through)
text-transformtext-transform: uppercase; Transforms letters (uppercase, lowercase, capitalize)
text-shadowtext-shadow: 2px 2px 4px #000; Adds a shadow to the text
Breaks and Overflow
text-overflowtext-overflow: ellipsis; Specifies how to mark clipped content (clip, ellipsis)
word-breakword-break: break-all; Specifies word break rules at line edges
overflow-wrapoverflow-wrap: break-word; Allows breaking long words to the next line
clearclear: both; Property for positioning elements around floating elements

CSS Fonts

CSS fonts determine the weight, size, and style of text. Choosing the right font greatly affects how readers experience a website. The right font can create a strong identity for your website (whether it is a store, company presentation, blog, etc.). Using a readable font is important, as fonts add value to your text.

EXAMPLE
RESULT

It is also important to choose the correct text color and size. On the web, it is not recommended to use multiple different fonts simultaneously; we can use one font for headings and another for paragraphs. Why specify multiple fonts? If the browser does not support the first font, it tries the next one in the list. Today, due to widespread support for modern fonts, this is less critical, but it remains a good practice.

Property Example Description
Basic Font Properties
font-familyfont-family: Arial, sans-serif; Specifies the font and fallback fonts
font-sizefont-size: 16px; Specifies the font size (px, em, rem, %)
font-stylefont-style: italic; Specifies the font style (normal, italic, oblique)
font-weightfont-weight: bold; Specifies the font weight (normal, bold, 100-900)
font-variantfont-variant: small-caps; Specifies the font variant (normal, small-caps, all-small-caps)
fontfont: italic bold 16px Arial; Shorthand syntax for all font properties
External Fonts
@import@import url("https://fonts.googleapis.com/css2?family=Roboto"); Imports an external font (e.g., Google Fonts)
@font-face@font-face { font-family: "MyFont"; src: url("font.woff2"); } Defines a custom font with a local file
Colors and Backgrounds
colorcolor: #333;Specifies the text color
background-colorbackground-color: #f0f0f0; Specifies the background color of the text
Hover Effects
:hovera:hover { color: red; font-weight: bold; } Changes properties on mouse hover