HTML, CSS and JavaScript: what each one does
Understand the three parts of a webpage with a small example you can read before you write any code.
One page, three different jobs
A webpage can combine content, presentation and behavior. HTML gives content structure and meaning. CSS controls presentation such as spacing and color. JavaScript can respond to actions and change what the page does. These roles work together, but they are not interchangeable.
HTML: identify the parts
HTML stands for HyperText Markup Language. An element usually has an opening tag, content and a closing tag. A heading helps describe the page’s structure; a real button tells the browser that the element is an action.
<h1>Welcome to my project</h1>
<button id="hello" type="button">Say hello</button>
<p id="message">Your message will appear here.</p>The words inside the tags are visible content. The id values identify elements so other code can refer to them. Using a real button gives you useful built-in behavior, including keyboard activation, without pretending that an ordinary box is a control.
CSS: choose how the parts look
CSS stands for Cascading Style Sheets. A selector chooses an element; declarations describe its presentation. This rule changes how the button looks:
button {
background: #f4be35;
color: #191919;
padding: 12px 20px;
}It does not make the button show a message. Visual styling should also make interaction clear. A noninteractive paragraph should not look like a purchase button, and a keyboard user needs to see which link or control has focus.
JavaScript: respond to the click
This example waits for a click and then changes the paragraph. It assumes the HTML elements above have already loaded:
const button = document.getElementById('hello');
const message = document.getElementById('message');
button.addEventListener('click', () => {
message.textContent = 'Hello, builder!';
});addEventListener registers code to run when an event happens. textContent updates text rather than treating the message as HTML. A click is an input; the changed paragraph is an output.
Predict before changing anything
- If you change the words inside
h1, which part of the page changes? - If you change the CSS background color, will the message behavior change?
- If you remove the JavaScript listener, what will clicking the button do in this example?
The heading text changes, the styling changes independently, and the button no longer runs this custom message action. Practice becomes more useful when you explain why a change worked rather than only copying the result.
This example runs entirely in a browser. Saving private records, verifying users or keeping API keys secret requires a server-side design too. Learn how that distinction informed the BuildAI project.
Read more: MDN: Your first website.