Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML5 <meta charset="utf-8"> #11479

Open
wants to merge 1 commit into
base: 6
Choose a base branch
from
Open

Conversation

lerni
Copy link
Contributor

@lerni lerni commented Nov 26, 2024

Description

<meta charset="utf-8"> should be used exclusively, instead of <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> or both as it is not needed for HTML5. W3C Validator also flags self-closing tags as an issue. While Symfony has reverted such a change, still it would make sense to remove those esp. in light of PHP 8.4 DOM HTML5 parsing. What is your opinion on handling self-closing tags?

Manual testing steps

A PR will follow in the CMS for ensuring HTML5 compliance. Additionally, simple theme should be updated to address this issue. Ultimately, only a single<meta charset="utf-8"> should be used.

Issues

#7438

Pull request checklist

  • The target branch is correct
  • All commits are relevant to the purpose of the PR (e.g. no debug statements, unrelated refactoring, or arbitrary linting)
    • Small amounts of additional linting are usually okay, but if it makes it hard to concentrate on the relevant changes, ask for the unrelated changes to be reverted, and submitted as a separate PR.
  • The commit messages follow our commit message guidelines
  • The PR follows our contribution guidelines
  • Code changes follow our coding conventions
  • This change is covered with tests (or tests aren't necessary for this change)
  • Any relevant User Help/Developer documentation is updated; for impactful changes, information is added to the changelog for the intended release
  • CI is green

@GuySartorelli
Copy link
Member

<meta charset="utf-8"> should be used exclusively, instead of <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> or both as it is not needed for HTML5.

Is there some docs or an RFC or something along those lines you could link me to for this?

What is your opinion on handling self-closing tags?

If there is clear, specific advice from an appropriately authoritative source, then we should follow that advice. In the absence of specific advice I'd be inclined to leave them how they are.

@lerni
Copy link
Contributor Author

lerni commented Dec 15, 2024

I think the links in #3031 should describe why to use <meta charset="utf-8"> instead of <meta http-equiv="Content-Type" content="text/html; charset=utf-8">.

Essentially, it's the way HTML5 is written those days. The longer version is a legacy from HTML4. The shorter version is recommended by the HTML5 specification, is easier to read and more concise. It's equally well supported and achieves the same result as the longer version.

As linked in #3031 W3C recommends not using trailing slashes on void elements. This is because it has no effect and interacts badly with unquoted attribute values.

  1. MDN Web Docs

  2. HTML Living Standard (WHATWG)

  3. W3C HTML5 Specification

The consensus across these sources is that trailing slashes on void elements:

  • Are unnecessary in HTML5
  • Add no semantic value
  • May cause issues with unquoted attributes
  • Should be omitted for cleaner, more consistent code

However, it's worth noting that DOMDocument versions before PHP 8.4 may not support void elements without trailing slashes, as linked above. I have no clear view on it, but sooner or later Silverstripe should follow the latest recommendations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants