Html id name length

What is a practical maximum length for HTML id?

But surely browsers, CSS implementations, and JavaScript toolkits must have some limits on the length they support. What is the smallest such limit that is safe to use in a HTML/CSS/JS application?

Javascript Solutions

Solution 1 — Javascript

Just tested: 1M characters works on every modern browser: Chrome1, FF3, IE7, Konqueror3, Opera9, Safari3.

I suspect even longer IDs could become hard to remember.

Solution 2 — Javascript

A practical limit, for me, is however long an ID I can store in my head during the time I’m working with the HTML/CSS.

This limit is usually between 8 and 13 characters, depending on how long I’ve been working and if the names make sense in the context of the element.

Solution 3 — Javascript

Sometimes I will end up with very long IDs, but I name them consistently to match their exact purpose.

div id="page"> div id="primary-content"> div> div id="secondary-content"> div> div id="search-form-and-primary-nav-wrapper"> form id="search-form"> form> ul id="primary-nav"> li id="primary-nav-about-us"> li> ul> div> a id="logo">img /> a> div> 

As you can see, the selectors are occasionally pretty long. But it’s so much easier IMHO than working with something like the YUI grids.css where you end up with IDs like #doc, #bd, #yui-main, etc.

Solution 4 — Javascript

If this is an academic question, it’s pretty interesting. but as far as best practices are concerned, you shouldn’t need to — or want to — stretch these out. If you need to store data about an HTML element, it’s better to put it into an attribute on the DOM object.

Читайте также:  Create html using notepad

Источник

Атрибуты minlength и maxlength

Атрибуты minlength и maxlength устанавливают полям ввода минимальное и максимальное количество символов.

Время чтения: меньше 5 мин

Это незавершённая статья. Вы можете помочь её закончить! Почитайте о том, как контрибьютить в Доку.

Кратко

Скопировать ссылку «Кратко» Скопировано

Атрибуты minlength и maxlength позволяют устанавливать минимальное и максимальное количество символов в полях ввода или .

Как пишется

Скопировать ссылку «Как пишется» Скопировано

  input minlength="4" maxlength="8"> textarea minlength="50" maxlength="1000">      

Пример

Скопировать ссылку "Пример" Скопировано

Создадим поле для ввода пароля и ограничим количество допустимых символов:

   type="password" name="password" required minlength="8" maxlength="16"> label for="password">Введите пароль (от 8 до 16 символов):label> input type="password" id="password" name="password" required minlength="8" maxlength="16" >      

Как понять

Скопировать ссылку "Как понять" Скопировано

Атрибуты minlength и maxlength устанавливают минимальное и максимальное количество символов в полях ввода или . Значением атрибутов должно быть целое число от 0 и выше. Если значение атрибутов не указано, или указано неправильно, ограничений по длине у поля не будет.

При добавлении полю обоих атрибутов, значение minlength всегда должно быть меньше значения maxlength . Если за этим не уследить, то поле всегда будет невалидным.

Источник

Оцените статью