LoginSignup
2
2

More than 5 years have passed since last update.

そういえばHTMLの属性って「"」か「'」どっちで囲めばいいの?

Posted at

結論から言えば

Attributes are placed inside the start tag, and consist of a name and a value, separated by an "=" character. The attribute value can remain unquoted if it doesn’t contain space characters or any of " ' ` = < or >. Otherwise, it has to be quoted using either single or double quotes. The value, along with the "=" character, can be omitted altogether if the value is the empty string.

sample
<!-- empty attributes -->
<input name=address disabled>
<input name=address disabled="">

<!-- attributes with a value -->
<input name=address maxlength=200>
<input name=address maxlength='200'>
<input name=address maxlength="200">

W3C勧告 HTML5.1 HTMLの簡単な紹介 より

結論から言えば、どちらでもOK。

しかしなぜ、"ダブルクオーテーション"の方が普及率が高いのか……
W3C勧告にダブルクオーテーションが使用されているから、というのが有力かなーと思っているのですが……
調べてみましたが、結局結論に至れず。うーん…

2
2
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2