HTML Button onClick - HTML Tutorial

HTML Button onClick

BLUF: Mastering HTML Button onClick is a fundamental step in becoming a web developer. This guide covers the structure, syntax, and best practices for using this HTML element effectively.
Key Lesson: HTML Button onClick

Web structure starts with solid HTML. Learn how HTML Button onClick contributes to accessible and semantic web pages in the tutorial below.

The HTML <button onclick=" "> attribute is designed for triggering a script upon clicking a button. This attribute enjoys universal support across all web browsers and is commonly employed to invoke a function upon button click events.

Syntax:

Example

<button onclick=" single value script">

Examples:

Example 1: The illustration below outlines the utilization of the button element:

Example

<!DOCTYPE HTML> 

<html> 

<head>  

<title> 

example of onclick button

</title> 

<script> 

function welcome() { 

window.open("");

} 

</script> 

</head> 

<body style = "text-align:center"> 

<button onclick="welcome()"> Welcome to our website </button>         

</body> 

</html>

Output:

Browser Support

Element Chrome IE Firefox Opera Safari
<onClick> Yes Yes Yes Yes Yes

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience