HTML and CSS are important technologies for customizing WordPress websites. HTML defines the structure of webpage content, while CSS controls its appearance, including colors, spacing, fonts, borders and responsive layouts.
HTML stands for HyperText Markup Language. It is used to structure webpage content using elements such as headings, paragraphs, links, images, lists and buttons.
<h1>Welcome to Our Institute</h1>
<p>We provide professional computer courses.</p>
<a href="/courses/">View Courses</a>
This code creates a heading, a paragraph and a link.
CSS stands for Cascading Style Sheets. It controls the visual presentation of HTML elements.
h1 {
color: blue;
font-size: 36px;
}
p {
color: #333333;
font-size: 18px;
}
The heading becomes blue and 36 pixels in size. Paragraph text becomes dark gray and 18 pixels in size.
| HTML | CSS |
|---|---|
| Defines webpage structure. | Controls webpage appearance. |
| Creates headings and paragraphs. | Changes fonts, colors and spacing. |
| Creates links and images. | Styles links and images. |
| Uses elements and attributes. | Uses selectors and declarations. |
Example: <h1>Hello</h1> |
Example: h1 { color: red; } |
WordPress allows you to add HTML in different places depending on your theme, editor and permissions.
<section>
<h2>Welcome to Soopro Pathshala</h2>
<p>
Learn computer skills and programming
with practical training.
</p>
<a href="/courses/">Explore Our Courses</a>
</section>
The method for adding CSS depends on your WordPress theme.
Suppose you want to make the main heading blue. You can use a CSS selector to target the heading.
h1 {
color: blue;
}
This rule targets all h1 elements matched
by the stylesheet. If you want to change only one
particular heading, use a suitable class or ID instead.
A CSS selector identifies the HTML elements that should receive a particular style.
| Selector | Example | Purpose |
|---|---|---|
| Element | p |
Selects matching paragraph elements. |
| Class | .course-card |
Selects elements with the course-card class. |
| ID | #main-heading |
Selects the element with that ID. |
| Descendant | .content-box p |
Selects paragraphs inside matching content boxes. |
| Hover | a:hover |
Applies styles when a link is hovered over. |
Classes are useful when you want to style multiple elements consistently. You can assign a class through the block's settings when the editor supports it.
<div class="course-card">
<h2>Web Development</h2>
<p>Learn HTML, CSS and JavaScript.</p>
</div>
.course-card {
background-color: #f0f8ff;
border: 1px solid #0d6efd;
padding: 20px;
border-radius: 10px;
}
.course-card h2 {
color: #0d6efd;
}
.course-card p {
color: #333333;
}
An ID identifies a particular element in a document. IDs should be unique within the page.
<h2 id="main-heading">
Our Popular Courses
</h2>
#main-heading {
color: green;
text-align: center;
font-size: 30px;
}
You can combine HTML and CSS to create a styled link that looks like a button. In this example, the button opens a courses page.
<a class="course-button" href="/courses/">
View Courses
</a>
.course-button {
display: inline-block;
background-color: #198754;
color: white;
padding: 12px 24px;
text-decoration: none;
border-radius: 6px;
font-weight: bold;
}
.course-button:hover {
background-color: #146c43;
color: white;
}
Responsive CSS helps a website adapt to different screen sizes. Media queries let you apply styles under particular viewport conditions.
.course-card {
width: 100%;
padding: 20px;
box-sizing: border-box;
}
@media (min-width: 768px) {
.course-card {
max-width: 600px;
margin: 0 auto;
}
}
This example keeps the card within its container and limits its width on wider screens. Test your layout at several viewport sizes to ensure it works as intended.
| Problem | Possible Solution |
|---|---|
| CSS changes do not appear. | Check the selector, stylesheet location and browser or caching plugin cache. |
| HTML markup is displayed as text. | Check whether the code was entered in a code or preformatted block instead of a Custom HTML block. |
| Styles affect too many elements. | Use a more specific class selector. |
| Design breaks on mobile. | Check widths, spacing, image sizes and media queries. |
| HTML or script content is removed. | Check user permissions, editor sanitization and applicable security restrictions. |
Use a WordPress test page to complete these tasks:
course-card to your course sections.Choose the correct answer for each question.