HTML Buttons

Clickable buttons and their types.

✍️ 3 exercises + code challenge in this lesson

The <button> element creates a clickable button. Unlike <input type="button">, it can contain text, icons and other elements.

The type attribute

  • type="submit" submits a form (the default inside a form).
  • type="reset" resets a form's fields.
  • type="button" does nothing by default; use it with JavaScript.

Add disabled to make a button unclickable.

Key Takeaways: HTML Buttons

Mastering HTML Buttons helps you write clean and reliable HTML code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.

HTML Buttons Code Example

HTML
<style>
  button { padding: 10px 18px; border: 0; border-radius: 8px; font-weight: bold; cursor: pointer; margin: 4px; }
  .primary { background: #2563EB; color: white; }
  .outline { background: white; border: 2px solid #2563EB; color: #2563EB; }
</style>

<button class="primary" type="button" onclick="alert('Hello!')">Say hello</button>
<button class="outline" type="button">Outline button</button>
<button disabled>Disabled</button>
Free sign-in required · Google login available

HTML Buttons Practice Exercises

Check what you learned in “HTML Buttons”.

/ 3 solved
Fill in the blank

Make this a button that does not submit a form.

<button ="">Click</button>
✓ Correct! Not quite. Try again.
Multiple choice

Which attribute makes a button unclickable?

✓ Correct! Not quite. Try again.
Code challenge

Add a disabled button with the text "Sold out".

Write the code in the live editor. Your answer is checked automatically.

Free sign-in required · Google login available

to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.

Stuck on something?

Ask the community in the CodesInTech forum.

Need a developer?

Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.

Explore Our Services