Introduction to <button>tag

The <button>tag is an HTML element that defines a clickable button. It can contain text, images, or any combination of HTML content, offering greater flexibility compared to the <input>element with a <type="button">attribute. This versatility makes the <button>tag a popular choice for developers looking to create more complex and styled buttons.

Copy to clipboard

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>title of <button> tag</title>
        <link rel="stylesheet" href="styles.css">
    </head>
    <body>
    
        <!-- Button Example -->
        <div class="button-container">
            <button class="beautiful-button">Click Me</button>
        </div>
    
    </body>
    </html>
Copy to clipboard
/* styles.css */
    
    /* Center the button on the page */
    .button-container {
        display: flex;
        justify-content: center;
        align-items: center;
        height: 100vh;
        background-color: #f0f2f5;
    }
    
    /* Beautiful Button Styling */
    .beautiful-button {
        padding: 15px 40px;
        font-size: 20px;
        color: #ffffff;
        background-image: linear-gradient(45deg, #ff6b6b, #f06595);
        border: none;
        border-radius: 50px;
        cursor: pointer;
        transition: all 0.3s ease;
        box-shadow: 0 8px 15px rgba(0, 0, 0, 0.1);
        position: relative;
        overflow: hidden;
        z-index: 1;
    }
    
    /* Adding Hover Effects */
    .beautiful-button:hover {
        background-image: linear-gradient(45deg, #f06595, #ff6b6b);
        box-shadow: 0 15px 25px rgba(0, 0, 0, 0.2);
        transform: translateY(-3px);
    }
    
    /* Button Active Effect */
    .beautiful-button:active {
        transform: translateY(1px);
        box-shadow: 0 5px 10px rgba(0, 0, 0, 0.1);
    }
    
    /* Pseudo-element for Ripple Effect */
    .beautiful-button::before {
        content: '';
        position: absolute;
        top: 50%;
        left: 50%;
        width: 300%;
        height: 300%;
        background: rgba(255, 255, 255, 0.15);
        transition: all 0.5s ease;
        border-radius: 50%;
        transform: translate(-50%, -50%) scale(0);
        z-index: 0;
    }
    
    /* Ripple Effect on Click */
    .beautiful-button:focus::before {
        transform: translate(-50%, -50%) scale(1);
        opacity: 0;
        transition: all 0.5s ease;
    }

Global Attributes

AttributesDescription
accesskeySpecifies a shortcut key to activate or focus an element.
autocapitalizeControls whether and how text input is automatically capitalized.
classSpecifies one or more class names for the element, allowing CSS styling and JavaScript manipulation.
contenteditableSpecifies whether the content of an element is editable or not.
contextmenuSpecifies a context menu for the element.
dirDefines the text direction. Possible values are "ltr" (left-to-right), "rtl" (right-to-left), and "auto".
draggableSpecifies whether an element is draggable. Possible values are "true" or "false".
enterkeyhintSpecifies the action label or icon to be shown for the enter key on virtual keyboards.
hiddenIndicates that the element is not yet, or is no longer, relevant. The browser does not display elements that have the `hidden` attribute set.
idSpecifies a unique identifier for the element.
inputmodeProvides a hint to browsers for which virtual keyboard configuration to use when editing this element or its descendants.
isAllows you to specify the type of custom element.
langSpecifies the language of the element's content.
nonceA cryptographic nonce ("number used once") that can be used by Content Security Policy (CSP) to determine whether or not a given fetch will be allowed to proceed.
partSpecifies the element’s part in the shadow DOM.
slotAssigns a slot in a shadow DOM shadow tree.
spellcheckIndicates whether the element is subject to spell checking.
styleProvides inline CSS styling for the element.
tabindexSpecifies the tab order of the element.
titleAdds extra information about the element, displayed as a tooltip when hovering over the element.
translateSpecifies whether the content of the element should be translated. Possible values are "yes" or "no".
HTML AttributesGlobal AttributesEvent Attributes
To view the full list
To view the full list
To view the full list
elementsChrome BrowsersMicrosoft Edge BrowserFirefox BrowsersSafari BrowserOpera Browser
<button>YesYesYesYesYes