W3docs

HTML checked-Attribut

The HTML checked attribute specifies that an <input> element must be checked when the page loads. See how you can use this attribute on the <input> element.

Das HTML checked-Attribut ist ein boolesches Attribut und gibt an, dass ein <input>-Element beim Laden der Seite markiert sein muss.

Sie können dieses Attribut nur auf dem <input>-Element (<input type="checkbox"> und <input type="radio">) verwenden.

Es ist auch möglich, das checked-Attribut nach dem Laden der Seite mit JavaScript festzulegen.

Syntax

<input type="checkbox|radio" checked>
<input type="checkbox|radio" checked="checked">

Beispiel für das HTML checked-Attribut:

HTML checked-Attribut

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
  </head>
  <body>
    <h2>HTML Form Example</h2>
    <form action="/form/submit" method="post">
      <input type="radio" name="game" value="football" checked /> Football
      <input type="radio" name="game" value="basketball" /> Basketball
      <input type="submit" value="Submit" />
    </form>
  </body>
</html>

Practice

Übung

Was bewirkt das HTML-'checked'-Attribut?