How to make HTML markup more semantic

I am wondering how I would be able to make this more semantic. My initial thought was change the <div class="container"> to a <main> and style that, and change the <div class="content"> to a <section>, but I’m not sure what would be best. Any resources to help understand semantic HTML are greatly appreciated as well. Thanks!

<body>
	<div class="container">
		<div class="content">
			<h1>Responsive layouts don't have to be a struggle</h1>
			<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore
				magna
				aliqua. Ut enim ad minim veniam.</p>
			<button class="cta-btn">I want to learn</button>
		</div>
	</div>
</body>

And my CSS here:

@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;700;900&display=swap');

*, *::before, ::after {
	box-sizing: border-box;
	padding: 0;
	margin: 0;
}

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

.container {
	width: 100%;
	max-width: 1440px;
	margin: 0 auto;
	background-color: #23424A;
	color: white;
}

.content {
	width: 50%;
	padding: 148px 0 148px 122px;
}

.content h1 {
	font-weight: 900;
	font-size: 48px;
	margin-bottom: 1rem;
}

.content p {
	font-size: 21px;
	line-height: 31px;
	margin-bottom: 3rem;
	color: #DEE2E5;
}

.cta-btn {
	border: none;
	border-radius: 31.5px;
	background-color: #38CFD9;
	color: #23424A;
	padding: 16px 48px;
	text-transform: uppercase;
	font-weight: 700;
	font-size: 21px;
}

.cta-btn:hover {
	background-color: #32bac3;
	cursor: pointer;
}

You definitely want all of your main content wrapped in a <main>. This is an accessibility best practice. You only need <section>s if you have several sections on the page. With just the code above it would be overkill to have a <section>.

1 Like

@bbsmooth Thanks - that makes sense. So just wrap everything in a <main> tag, and then maybe replace the <div class="content"> with a class of container instead? (Just seems to make more sense that way IMO)

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.