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 7970273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:22:20+00:00 2026-06-04T07:22:20+00:00

While working on my project I’ve found out that \n in html source is

  • 0

While working on my project I’ve found out that \n in html source is displayed as space between these 2 lines in browsers. For example,

a
b

in browsers is displayed as a b. How can I avoid this “space” without removing line-break? The result I want is ab right next to each other — not on separate lines, not with a space between them.

I generate quite big form on fly using php, for readability, I use PHP_EOL that is the same as \n, but in browsers appears extra white-spaces. I want to get rid of them.

  • 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-04T07:22:21+00:00Added an answer on June 4, 2026 at 7:22 am

    Updated answer:

    In the comments below you’ve said that the result you’re looking for is “ab” right next to each other, with no space or line break at all between them.

    If “a” and “b” are really text, I don’t believe you have any option, you have to remove the linebreak if you want them next to each other. (I realize you said you didn’t want to do that, I’m just saying, I don’t think you have a choice.)

    If “a” and “b” are elements (you’ve said you’re outputting a big form), you can play games with negative CSS margins, but it gets ugly fast. Or the old trick of moving that line break into a tag, e.g.:

    <input name="a" type="text"
    ><input name="b" type="text"
    >
    

    The line break within the tag is not displayed (because it’s in a tag, not text).

    The link below on inter-element whitespace may also help, depending on your overall markup; basically there are times the browser will disregard whitespace between elements, so you might be able to adjust things slightly to make it do that.

    You’ve said you’re using it for readability. I suppose another option, although it’s really verbose, is to put the line break in a comment:

    form field here<!--
    -->next form field here<!--
    -->next form field here
    

    …but again, quite verbose (and probably not doing much for readability).

    Your best bet is what you said you don’t want: Remove the linebreak. 🙂

    Original answer:

    (From when it was unclear that you wanted “ab” right next to each other; just about everyone thought you wanted to have the line break shown.)

    Why is space shown in browsers when in source code ‘\n’ is used?

    Because the HTML standard says that all sequences of whitespace characters (other than inter-element whitespace) are treated as a single space. So for HTML, a newline, space, tab, carriage return, and formfeed are all exactly equal: They’re displayed as a space.

    How can I avoid this “space” without removing line-break?

    There are a few ways:

    1. You can use a br element:

      a<br>b
      
    2. You can put a and b in separate containers that use block display (both p and div do by default, and you can use CSS to apply display: block to others).

      <p>a</p>
      <p>b</p>
      

      or

      <div>a</div>
      <div>b</div>
      

      etc

    3. If you really want that newline to be treated as a line break, you can use a pre element, which has special handling of pre-formatted text

      <pre>a
      b</pre>
      

      …and you can apply that same sort of handling to other elements using CSS’s white-space style (values pre, pre-wrap, and pre-line).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Got these lines while working in a project automatically created by Flash Develop. Not
I know that it might sound silly but, while working on project at some
While working on my first project that completely uses css for layout rather than
While working on a project that will store a whole bunch of (completely different)
I just found something that sounds weird with Maven plugin management. While working on
While working on a small project I found myself needing to do some custom
While working on my project, I created 3 mini-libraries (100-1000 lines). They are quite
while working on a project I accidentally noticed that the same method with only
While working a project tonight, I ended up using one .js resource file for
While working on an Xcode project i keep getting the spinning wheel while switching

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.