Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7819355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:55:00+00:00 2026-06-02T06:55:00+00:00

What should be done against contents of href attribute: HTML or URL encoding? <a

  • 0

What should be done against contents of href attribute: HTML or URL encoding?

<a href="???">link text</a>

On the one hand, since href attribute contains URL I should use URL encoding.
On the other hand, I’m inserting this URL into HTML, so it must be HTML encoded.

Please help me to overcome this contradiction.

Thanks.


EDIT:

Here’s the contradiction. Suppose there might be the ‘<‘ and ‘>’ characters in the URL. URL encoding won’t escape them, so there will be reserved HTML characters inside the href attribute, which violates the standard. HTML encoding will escape ‘<‘ and ‘>’ characters and HTML will be valid, but after that there will be unexpected ‘&’ characters in the URL (this is reserved character for URL, it’s used as a delimiter of query string parameters).

Reserved URL characters forms a superset of reserved HTML characters except for the ‘<‘ and ‘>’ that are reserved for HTML but not for URL.


EDIT 2:

I was wrong about ‘<‘ and ‘>’ characters, they are actually percent escaped by URL encoding. If so, URL encoding is sufficient in this case, isn’t it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T06:55:03+00:00Added an answer on June 2, 2026 at 6:55 am

    Construct a URL as normal. Follow the rules for constructing URLs. Encode data you put into it.

    Then construct HTML as normal. Follow the rules for constructing HTML. Encode data as you put it into it.

    i.e. Do both (but in the right order).

    They aren’t mutually exclusive, so there is no contradiction.

    For example (this is a simplified example that assumes data in $_GET is correct and exists, don’t do that in the real world):

    $search_term = $_GET['q'];
    $page = $_GET['page'];
    $next_page = $page + 1;
    $next_page_url = 'http://example.com/search?q=' . urlencode($search_term) . '&page=' . urlencode($next_page);
    $html = '<a href="' . htmlspecialchars($next_page_url) . '">link text</a>';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to protect some subdomains from the public. Restriction should be done against
I'm trying to start unit testing on my application (should have done so from
I'm still trying to wrap my head around how things should be done in
I've curious how this should be properly done. I ran a page im working
I'm a newcomer to Python but I understand that things should not be done
Can this be done? It seems like this should be possible. In general, I
In your opinion, should the documents listing what further needs to be done on
I've heard people advise that one should always use the Iterator pattern to control
I have an SQL script (currently running against SQLite, but it should probably work
I've been bashing my head against this one for a while now. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.