Questions
28 of 30
1How can you centre text vertically and horizontally inside a box?
2What is the use of the white-space property?
3How can you truncate text with an ellipsis (...) in CSS?
4How do you wrap or prevent wrapping of text in a container?
5How do you make text responsive across different screen sizes?
6How do you justify text using CSS?
7What does text-shadow do? Give an example.
8How can you apply multiple shadows to text?
9How do you apply gradients to text in CSS?
10How do you control text overflow in a fixed-width container?
11What is the difference between em, rem, and px when styling text?
12How does font-weight differ from <b> tag in semantic meaning?
13How does accessibility relate to text formatting in HTML?
14What’s the difference between semantic and non-semantic text formatting tags?
15How can you ensure consistent text appearance across different browsers?
16What is the difference between font-style, font-variant, and font-weight?
17What is the role of @font-face in web typography?
18How can you import custom fonts in CSS?
19What’s the impact of using web fonts on performance?
20How can you optimise text rendering for readability?
21How do you make text appear vertically (top-to-bottom) using CSS?
22How do you style only the first letter or first line of a paragraph?
23How do you create a drop cap effect?
24How can you highlight a selected text range dynamically?
25How do you make text glow or have a neon effect using CSS?
26What CSS properties can you use for text animations?
27How can you apply a gradient background only to the text and not the entire element?
28How can you apply different styles to different words in the same line?
29How do you prevent text selection on a webpage?
30How do you implement responsive typography (fluid text size)?
28 / 30

How can you apply different styles to different words in the same line?

Styling Individual Words within a Line Using CSS

CSS allows you to style different words in the same line by wrapping each word (or phrase) in a <span> and applying separate classes or inline styles. This gives you fine-grained control over color, font, size, or other text properties without breaking the line.

Key Techniques
  1. 1

    Wrap the words you want to style individually in <span> elements.

  2. 2

    Assign classes or IDs to each <span> for custom styling.

  3. 3

    Use CSS properties like color, font-weight, font-style, text-decoration, text-shadow, or background-clip for visual effects.

  4. 4

    Maintain semantic HTML: do not use spans unnecessarily for non-styling purposes.

  5. 5

    Combine with pseudo-elements (::first-letter, ::first-line) if partial styling of words or lines is needed.

Example: Styling Different Words

In this example, the word 'highlighted' is styled with a pink italic color, while 'bold' is styled with a bold purple color. Using spans allows multiple styles within the same line without affecting layout or semantic structure.

Best Practices
  1. 1

    Use <span> only for styling purposes to keep HTML semantic.

  2. 2

    Keep styles consistent for readability and accessibility.

  3. 3

    Avoid excessive inline styling; prefer CSS classes for maintainability.

  4. 4

    Test styles across browsers to ensure consistent appearance.

  5. 5

    Combine with CSS variables if multiple words share color schemes or effects.