Mastering Web Design: Fonts, Colors, and Backgrounds in CSS


Design Begins With CSS
HTML creates the structure of a web page.
But with HTML alone, you can only create a simple, undecorated screen.
For example, headings and paragraphs will appear but all in the same font and color.
Most of the work to make a website visually appealing is done by CSS.
In this lesson, we'll learn about three of the most commonly used design elements:
Fonts
Colors
Backgrounds
Understanding these three can completely transform your webpage's atmosphere.
Changing Text Color
To change text color, use the color property.
h1{
color:blue;
}
This code changes all <h1> tags to blue.
Simply changing the color can significantly alter a webpage's feel.
Various Ways to Specify Colors
CSS offers several ways to define colors.
Color Names
color:red;
HEX Codes
color:#154B95;
This is the most commonly used method in professional work.
RGB
color:rgb(21,75,149);
RGBA
color:rgba(21,75,149,0.7);
The last number represents transparency.
0 is completely transparent, 1 is fully opaque.
Changing Font Size
To change text size, use the font-size property.
h1{
font-size:40px;
}
The larger the number, the bigger the text.
Headings typically use 30-50px, while body text is usually 16-18px for readability.
Changing Font Family
To change fonts, use the font-family property.
body{
font-family:Arial;
}
However, in real websites, Google Fonts are commonly used instead of standard system fonts.
For example:
font-family:"Noto Sans KR", sans-serif;
This applies a clean Korean font.
Changing Font Weight
To adjust text thickness, use font-weight.
font-weight:bold;
Or:
font-weight:700;
The higher the number, the bolder the text.
Aligning Text
To position text, use text-align.
text-align:center;
Available values include:
left
center
right
Headings often use center alignment, while body text typically uses left alignment.
Adjusting Line Height
To make body text more readable, line height is frequently adjusted.
line-height:1.8;
If lines are too close together, it's hard to read; if too far apart, it can disrupt focus.
Typically, 1.5-1.8 is used for optimal readability.
Changing Background Color
To change the background color, use background-color.
body{
background-color:#f5f5f5;
}
Simply changing the background color can create a much cleaner appearance.
Many sites use very light gray instead of white for backgrounds.
Adding Background Images
Backgrounds can also include images.
body{
background-image:url("bg.jpg");
}
The image can be displayed across the entire screen or just a specific area.
Preventing Background Image Repetition
By default, background images repeat.
To prevent this, use:
background-repeat:no-repeat;
This stops the image from repeating across the screen.
Setting Background Size
To fill the entire screen with a background image, use:
background-size:cover;
This is commonly used for responsive websites.
Combining Multiple Properties
You can apply multiple properties at once, like this:
body{
font-family:"Noto Sans KR", sans-serif;
font-size:16px;
color:#333;
background-color:#f7f9fc;
}
This is the most commonly used code for setting a website's default style.
Styling Buttons
HTML
<button>Start</button>
CSS
button{
background:#154B95;
color:white;
font-size:18px;
}
A simple button becomes much more appealing with CSS styling.
In future lessons, we'll add borders, shadows, and animations.
Using Google Fonts
Websites commonly use Google Fonts instead of default system fonts.
Popular Korean fonts include:
Noto Sans KR
Nanum Gothic
Pretendard
Google Fonts ensures consistent font display across different operating systems.
Common Beginner Mistakes
1. Confusing color and background-color
color
changes text color,
background-color
changes background color.
2. Omitting units like px
font-size:20;
should be written as:
font-size:20px;
with units included.
3. Missing the # in HEX codes
154B95
should be written as:
#154B95
with the # symbol.
4. Forgetting semicolons after properties
Always include a semicolon at the end of each property to avoid errors.
Key Takeaways From This Lesson
Let's review what we've learned today:
colorchanges text color.font-sizesets text size.font-familychanges fonts.font-weightadjusts text thickness.text-aligncontrols text alignment.line-heightadjusts spacing between lines.background-colorsets background color.background-imageadds a background image.background-size: coveris commonly used to fill the screen with an image.
These properties are fundamental in CSS, so practicing them thoroughly will greatly improve your web design skills.
In Closing
In this lesson, we learned how to style websites using fonts, colors, and backgrounds with CSS.
While these designs are simple, mastering these basic properties can significantly enhance a website's overall quality.
In the next lesson, we'll explore the Box Model (margins, padding, borders), which is essential for controlling spacing and sizing between elements. This fundamental concept will help create clean, well-structured layouts.
FAQ
Why is Google Fonts recommended over standard system fonts?
Google Fonts ensures consistent font display across different operating systems and devices.
What does the 'rgba' color format do?
RGBA includes an alpha channel for transparency, where the fourth value (0-1) controls opacity.
Korean Source
This article is an English localization of a Korean-language report from BlogScore. Original: [Html/CSS 강좌] 8강 글꼴(Font), 색상(Color), 배경(Background) 꾸미기