C

CSS Handbook

Clean • Professional

CSS Text & Fonts — Interview Questions & Answers

3 minute

CSS Text & Fonts — Interview Questions & Answers

Ques: What are the main text properties in CSS?

Ans: CSS provides several properties to control the appearance and alignment of text, such as:

PropertyDescriptionExample
colorSets text colorcolor: navy;
text-alignAligns texttext-align: center;
text-transformChanges casetext-transform: uppercase;
text-decorationAdds decoration (underline, line-through)text-decoration: underline;
letter-spacingSpace between lettersletter-spacing: 2px;
line-heightSpace between linesline-height: 1.6;

Ques: How do you align text in CSS?

Ans: Use the text-align property.

ValueDescription
leftAligns text to the left (default)
rightAligns text to the right
centerCenters the text
justifyAligns text evenly on both sides

Example:

p {
  text-align: justify;
}

Ques: What is text-transform in CSS?

Ans: It controls the capitalization of text.

ValueDescription
uppercaseConverts all letters to uppercase
lowercaseConverts all letters to lowercase
capitalizeCapitalizes the first letter of each word

Example:

h2 {
  text-transform: capitalize;
}

Ques: How do you underline or remove underline from text?

Ans: Use the text-decoration property.

ValueDescription
underlineAdds underline
noneRemoves underline
line-throughAdds strike-through
overlineAdds a line above text

Example:

a {
  text-decoration: none;
}

Ques: What is text-shadow in CSS?

Ans: text-shadow adds shadow effects to text.

Syntax:

text-shadow: horizontal-offset vertical-offset blur color;

Example:

h1 {
  text-shadow: 2px 2px 5px gray;
}

Ques: What is line-height and why is it important?

Ans: line-height defines the space between lines of text.

It improves readability and visual spacing.

Example:

p {
  line-height: 1.8;
}

Ques: What are generic font families in CSS?

Ans: Generic font families are broad categories of fonts:

FamilyDescription
serifHas small strokes at the end of letters (e.g., Times New Roman)
sans-serifClean and modern (e.g., Arial, Helvetica)
monospaceFixed-width characters (e.g., Courier New)
cursiveImitates handwriting
fantasyDecorative or creative styles

Example:

p {
  font-family: "Arial", sans-serif;
}

Ques: How does font-family property work?

Ans: Specifies a priority list of fonts — the browser picks the first available one.

Example:

body {
  font-family: "Roboto", "Helvetica Neue", sans-serif;
}

Ques: What is the difference between serif and sans-serif fonts?

Font TypeExampleDescription
SerifTimes New RomanTraditional, formal, better for print
Sans-serifArial, RobotoClean, modern, better for screens

Ques: How can you add custom fonts in CSS?

Ans: Use the @font-face rule to load custom web fonts.

Example:

@font-face {
  font-family: 'MyFont';
  src: url('MyFont.woff2') format('woff2');
}

body {
  font-family: 'MyFont', sans-serif;
}

Ques: What is Google Fonts and how to use it?

Ans: Google Fonts provides free, web-hosted fonts that can be linked directly.

Example:

<link href="<https://fonts.googleapis.com/css2?family=Poppins:wght@400;600&display=swap>" rel="stylesheet">
body {
  font-family: "Poppins", sans-serif;
}

Ques: What are variable fonts?

Ans: Variable fonts are single font files containing multiple weights and styles, allowing dynamic changes via CSS.

Example:

p {
  font-variation-settings: "wght" 700;
}

Ques: What is font-weight, font-style, and font-variant?

PropertyDescriptionExample
font-weightControls boldnessfont-weight: 700;
font-styleItalic or normalfont-style: italic;
font-variantSmall caps effectfont-variant: small-caps;

Ques: How do you control spacing in text?

PropertyDescriptionExample
letter-spacingSpace between charactersletter-spacing: 1px;
word-spacingSpace between wordsword-spacing: 5px;
line-heightSpace between linesline-height: 1.6;

Ques: What are CSS icons and how are they added?

Ans: You can add icons using:

  1. Font Awesome
  2. SVG Icons
  3. Icon Fonts

Example (Font Awesome):

<i class="fa fa-home"></i>

Example (SVG):

<svg width="24" height="24">
  <circle cx="12" cy="12" r="10" fill="blue"/>
</svg>

 

Article 0 of 0