The problem isn't in your CSS, it's the new line after you close the </code> part. If you remove it, the space will disappear. This happens because text in a pre element is displayed in a fixed-width font, and it preserves both spaces and line breaks.

<html>

<head>
<!-- CSS --> 
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.9.0/themes/prism-coy.css" />

<!-- JS --> 
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.9.0/prism.min.js"></script>

<style>
pre{margin:0px;border:2px solid red;}
pre::before,pre::after,code::before,code::after{height:0!important;}
pre[class*="language-"]:before, pre[class*="language-"]:after{height:0px!important;display:inline-block;}
code{border-bottom:2px solid green;}
</style>

</head>
<body>

<pre class="brush: html line-numbers  language-html">
<code ="language-html">&lt;html&gt;
&lt;head&gt;&lt;/head&gt;
&lt;body&gt;
Hi, my name is Peter Martin. 
This is my first program in HTML.
&lt;/body&gt;
&lt;/html&gt;</code></pre>

</body>
</html>

Answer from Jonas Grumann on Stack Overflow
🌐
Browserling
browserling.com › tools › remove-all-whitespace
Remove All Whitespace - Delete Spaces, Tabs, Newlines - Online - Browserling Web Developer Tools
World's simplest online whitespace, tab, and newline deleter for web developers and programmers. Just paste your text in the form below, press the Remove All Spaces button, and you'll get back a single string with no spaces. Press a button – ...
🌐
HTML Code Generator
html-code-generator.com › tools › remove-empty-lines
Online Tool Remove Empty Lines And Trailing Spaces Instantly
It removes empty lines and whitespace, trailing spaces outside of these blocks to ensure a clean and compact output. ... Paste your HTML content into the input box. Select Options. (Preserve Tags, Trim Start of Lines, ...) Click the "Remove Empty Lines" button. Download or copy the cleaned HTML with all unnecessary blank lines removed.
People also ask

Can I remove all spaces, including between words?
Yes, our tool provides an option to remove all spaces, including the spaces between words.
🌐
testmu.ai
testmu.ai › home › free tools › remove spaces
Free Online Remove Spaces Tool - Delete Extra Spaces and Whitespace ...
Does this tool remove tabs and newlines as well?
Absolutely! The tool removes tabs, newlines, and any other whitespace characters to ensure a completely clean result.
🌐
testmu.ai
testmu.ai › home › free tools › remove spaces
Free Online Remove Spaces Tool - Delete Extra Spaces and Whitespace ...
When should I use this whitespace cleaner?
It’s useful when pasting text from PDFs, spreadsheets, code editors, or websites where spacing often breaks or becomes inconsistent.
🌐
textfixer.com
textfixer.com › tools › remove-white-spaces.php
Remove Spaces Online from Text - Delete Blank Space
🌐
Smart Web Solutions
smartwebsolutions.org › remove-spaces
White space Remover online-Delete extra spaces/tabs/lines from the text
How Quickly and easily remove white spaces/extra spaces/new lines from your text/html code. Online tool that remove multiple double spaces, empty space in the line beginning and line end and delete empty lines.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › CSS › Guides › Text › Whitespace
Handling whitespace - CSS - MDN Web Docs
The following JavaScript code shows several functions that deal with whitespace in the DOM: ... /** * Throughout, whitespace is defined as one of the characters * "\t" TAB \u0009 * "\n" LF \u000A * "\r" CR \u000D * " " SPC \u0020 * * This does not use JavaScript's "\s" because that includes non-breaking * spaces (and also some other characters).
🌐
Code Beautify
codebeautify.org › remove-extra-spaces
Remove Extra Spaces Online: Whitespace and Tab
Best Remove Extra Spaces and Tab Online Tool to remove unnecessary spaces, white space and tab from provided texts.
🌐
TextFixer
textfixer.com › tools › remove-white-spaces.php
Remove Spaces Online from Text - Delete Blank Space
Use this free tool to remove extra spaces or tab spaces from your text content. It replaces multiple spaces in your text with a single whitespace.
Find elsewhere
🌐
Testmu
testmu.ai › home › free tools › remove spaces
Free Online Remove Spaces Tool - Delete Extra Spaces and Whitespace from Text
Remove all spaces, tabs, and extra whitespace from text instantly with our free online Remove Spaces tool. Clean up and optimize your text with real-time results.
🌐
TestingBot
testingbot.com › free online tools › remove all whitespace
Remove All Whitespace - Delete Spaces, Tabs and Newlines
This tool will remove all the whitespace from the text you enter in the box below. Tabs, spaces, newlines will be removed. You will receive a spaceless string back. Welcome to the online whitespace, tab and newline remover tool.
🌐
Online Mini Tools
onlineminitools.com › html-cleaner
HTML Cleaner Online - Remove Extra Spaces, Blank Lines and Tags
Trim trailing whitespace – removes spaces and tabs at the end of every line. Remove all blank lines – flattens the result to a continuous block of non-empty lines. Strip HTML tags – removes every element to leave plain text.
🌐
Media College
mediacollege.com › internet › javascript › form › remove-spaces.html
How to Remove Spaces From a Text Field
Any spaces entered by the user will be removed when they click anywhere outside the text field. (See also: remove unwanted extra spaces.) ... <script language="javascript" type="text/javascript"> function removeSpaces(string) { return string.split(' ').join(''); } </script>
🌐
W3Schools
w3schools.com › tools › tool_whitespace_cleaner.php
Whitespace Cleaner - W3Schools
Trim each line Collapse multiple spaces Remove blank lines Remove all line breaks Tabs to spaces Spaces to tabs Strip all whitespace ... Whitespace characters such as spaces, tabs, and line breaks are invisible but can cause real problems. Copy-pasted text often contains inconsistent indentation, double spaces, or stray blank lines that break layouts and make data hard to process. This tool applies the operations you select in order, letting you normalize text for code, CSV files, or content editing.
🌐
freeCodeCamp
forum.freecodecamp.org › html-css
How do i remove this blank space? - HTML-CSS - The freeCodeCamp Forum
April 10, 2022 - Hello! I’ve been struggling with removing this space between this two sections. I have a feeling that is something pretty simple in my code but i’m not getting it! Can someone please help me? https://codepen.io/eutudo9…
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › API › Document_Object_Model › Whitespace
Handling whitespace - CSS | MDN
The following JavaScript code shows several functions that deal with whitespace in the DOM: ... /** * Throughout, whitespace is defined as one of the characters * "\t" TAB \u0009 * "\n" LF \u000A * "\r" CR \u000D * " " SPC \u0020 * * This does not use JavaScript's "\s" because that includes non-breaking * spaces (and also some other characters).
🌐
Dostring
dostring.com › remove-extra-spaces
Remove Extra Spaces Tool
Remove Extra Spaces · Clear All · Cleaned Text: · Made with ❤️ by · Json Parser Pro
🌐
Google Support
support.google.com › sites › thread › 270093154 › how-to-remove-blank-space-html
How to remove blank space(html) - Sites Community
Skip to main content · Sites Help · Sign in · Google Help · Help Center · Community · Sites · Terms of Service · Submit feedback · Send feedback on