HTML & CSS · Beginner · 15 min
Wrap long text in a narrow card
Keep a long URL and a reference code readable on a small screen.
See why the text overflows
A paragraph normally wraps at spaces and other suitable break points. A long URL segment or reference code can be wider than the card because it has no place to break. Try the narrow preview to see where the text extends past the border.
<p class="resource-text">https://example.invalid/library/BeginnerWorkshopResourcesAndReadingNotesForNovember2026</p>Expected appearance
Without extra wrapping, the long path segment can extend past the card.
Let long text wrap when it needs to
Use overflow-wrap: anywhere to let a long unbroken string continue on the next line when it would otherwise overflow. Text still uses its normal break points when they are available. The browser wraps the display without changing the URL or adding a hyphen.
.resource-text {
overflow-wrap: anywhere;
}Expected appearance
The whole address and reference code remain inside the card.
Try it yourself
Code runs on this device. When you are signed in, drafts sync to your account.
Edit the page content and include CSS in a style element. The preview supports a limited set of HTML elements. Scripts, external resources, navigation to other sites, and form submission are disabled.
Build and check
Keep the card and both .resource-text paragraphs. Add overflow-wrap: anywhere to .resource-text. Keep the URL and reference code exactly as provided. Both paragraphs must fit inside the card at 320px.
Add one .resource-text rule so the same wrapping behavior applies to both paragraphs.
Show worked solution
<style>
.resource-card {
box-sizing: border-box;
max-width: 30rem;
margin: 1rem auto;
padding: 1rem;
border: 1px solid #64748b;
font-family: sans-serif;
line-height: 1.5;
}
.resource-text { overflow-wrap: anywhere; }
</style>
<main class="resource-card">
<h1>Workshop resources</h1>
<h2>Resource address</h2>
<p class="resource-text resource-url">https://example.invalid/library/BeginnerWorkshopResourcesAndReadingNotesForNovember2026</p>
<h2>Reference code</h2>
<p class="resource-text resource-code">LIBRARYWORKSHOPREFERENCE2026NOVEMBERREADINGGROUPSESSIONB</p>
</main>The shared rule lets both long strings wrap inside the card. It changes where the lines break while keeping every character.
Page preview
Run to preview your page. Check tests the task requirements, including the requested screen widths. Check results do not replace keyboard and visual review.
Try it yourself
- Run the starter in the narrow preview and look for text outside the border. Apply the rule and preview it again.
- Check that both strings remain readable and that no characters were removed or replaced.