The Battle of Trafalgar was an important part of the Napoleonic Wars. It was an important military loss for Napoleon because it prevented him from invading England and because it guaranteed that the British would retain naval supremacy for the remainder of the war (a major reason they were able to win the war).
When the Battle of Trafalgar happened in 1805, France was the strongest military power on the continent of Europe. By contrast, Britain's major strength was naval. If the French could break the naval strength of the British, the power of their army would likely have been used to invade England.
At the Battle of Trafalgar, the British destroyed much of the combined French and Spanish fleets. By doing so, they kept naval superiority and made a French invasion of England impossible.